File coreutils-ls-restore-8.31-behavior-on-removed-dirs.patch of Package coreutils

Upstream commits (squashed) after the release of coreutils-8.32:
  [PATCH 1/2] ls: restore 8.31 behavior on removed directories
  [PATCH 2/2] ls: improve removed-directory test
Remove this patch with the next coreutils release.

Discussed at:
  https://lists.gnu.org/archive/html/bug-coreutils/2020-03/msg00008.html

Upstream commits:
  https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=10fcb97
  https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=672819c

commit 672819c73f2e94e61386dc0584bddf9da860cc26 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Sat Mar 7 10:29:51 2020 -0800

    ls: improve removed-directory test
    
    * tests/ls/removed-directory.sh: Remove host_triplet test.
    Skip this test if one cannot remove the working directory.
    From a suggestion by Bernhard Voelker (Bug#39929).

commit 10fcb97bd728f09d4a027eddf8ad2900f0819b0a
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Thu Mar 5 17:25:29 2020 -0800

    ls: restore 8.31 behavior on removed directories
    
    * NEWS: Mention this.
    * src/ls.c: Do not include <sys/sycall.h>
    (print_dir): Don't worry about whether the directory is removed.
    * tests/ls/removed-directory.sh: Adjust to match new (i.e., old)
    behavior.
---
 NEWS                          |    9 +++++++++
 src/ls.c                      |   22 ----------------------
 tests/ls/removed-directory.sh |   23 ++++++-----------------
 3 files changed, 15 insertions(+), 39 deletions(-)

Index: NEWS
===================================================================
--- NEWS.orig
+++ NEWS
@@ -1,5 +1,14 @@
 GNU coreutils NEWS                                    -*- outline -*-
 
+* Noteworthy downstream changes (on top of upstream coreutils-8.32)
+
+** Changes in behavior
+
+  On GNU/Linux systems, ls no longer issues an error message on
+  directory merely because it was removed.  This reverts a change
+  that was made in release 8.32.
+
+
 * Noteworthy changes in release 8.32 (2020-03-05) [stable]
 
 ** Bug fixes
Index: src/ls.c
===================================================================
--- src/ls.c.orig
+++ src/ls.c
@@ -49,10 +49,6 @@
 # include <sys/ptem.h>
 #endif
 
-#ifdef __linux__
-# include <sys/syscall.h>
-#endif
-
 #include <stdio.h>
 #include <assert.h>
 #include <setjmp.h>
@@ -2896,7 +2892,6 @@ print_dir (char const *name, char const
   struct dirent *next;
   uintmax_t total_blocks = 0;
   static bool first = true;
-  bool found_any_entries = false;
 
   errno = 0;
   dirp = opendir (name);
@@ -2972,7 +2967,6 @@ print_dir (char const *name, char const
       next = readdir (dirp);
       if (next)
         {
-          found_any_entries = true;
           if (! file_ignored (next->d_name))
             {
               enum filetype type = unknown;
@@ -3018,22 +3012,6 @@ print_dir (char const *name, char const
           if (errno != EOVERFLOW)
             break;
         }
-#ifdef __linux__
-      else if (! found_any_entries)
-        {
-          /* If readdir finds no directory entries at all, not even "." or
-             "..", then double check that the directory exists.  */
-          if (syscall (SYS_getdents, dirfd (dirp), NULL, 0) == -1
-              && errno != EINVAL)
-            {
-              /* We exclude EINVAL as that pertains to buffer handling,
-                 and we've passed NULL as the buffer for simplicity.
-                 ENOENT is returned if appropriate before buffer handling.  */
-              file_failure (command_line_arg, _("reading directory %s"), name);
-            }
-          break;
-        }
-#endif
       else
         break;
 
Index: tests/ls/removed-directory.sh
===================================================================
--- tests/ls/removed-directory.sh.orig
+++ tests/ls/removed-directory.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
-# If ls is asked to list a removed directory (e.g. the parent process's
-# current working directory that has been removed by another process), it
-# emits an error message.
+# If ls is asked to list a removed directory (e.g., the parent process's
+# current working directory has been removed by another process), it
+# should not emit an error message merely because the directory is removed.
 
 # Copyright (C) 2020 Free Software Foundation, Inc.
 
@@ -21,25 +21,14 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
-case $host_triplet in
-  *linux*) ;;
-  *) skip_ 'non linux kernel' ;;
-esac
-
-LS_FAILURE=2
-
-cat <<\EOF >exp-err || framework_failure_
-ls: reading directory '.': No such file or directory
-EOF
-
 cwd=$(pwd)
 mkdir d || framework_failure_
 cd d || framework_failure_
-rmdir ../d || framework_failure_
+rmdir ../d || skip_ "can't remove working directory on this platform"
 
-returns_ $LS_FAILURE ls >../out 2>../err || fail=1
+ls >../out 2>../err || fail=1
 cd "$cwd" || framework_failure_
 compare /dev/null out || fail=1
-compare exp-err err || fail=1
+compare /dev/null err || fail=1
 
 Exit $fail
openSUSE Build Service is sponsored by