Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 1 | From 7c273e5c6041f8c70f73f5b280fbb8f27d9b5a36 Mon Sep 17 00:00:00 2001 |
| 2 | From: Paul Eggert <eggert@cs.ucla.edu> |
| 3 | Date: Thu, 5 Mar 2020 17:25:29 -0800 |
| 4 | Subject: [PATCH] ls: restore 8.31 behavior on removed directories |
| 5 | |
| 6 | * NEWS: Mention this. |
| 7 | * src/ls.c: Do not include <sys/sycall.h> |
| 8 | (print_dir): Don't worry about whether the directory is removed. |
| 9 | * tests/ls/removed-directory.sh: Adjust to match new (i.e., old) |
| 10 | behavior. |
| 11 | |
| 12 | Upstream-Status: Backport [https://github.com/coreutils/coreutils/commit/10fcb97bd728f09d4a027eddf8ad2900f0819b0a] |
| 13 | Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> |
| 14 | --- |
| 15 | src/ls.c | 22 ---------------------- |
| 16 | tests/ls/removed-directory.sh | 10 ++-------- |
| 17 | 2 files changed, 2 insertions(+), 30 deletions(-) |
| 18 | |
| 19 | diff --git a/src/ls.c b/src/ls.c |
| 20 | index 637fe7a..0111f49 100644 |
| 21 | --- a/src/ls.c |
| 22 | +++ b/src/ls.c |
| 23 | @@ -49,10 +49,6 @@ |
| 24 | # include <sys/ptem.h> |
| 25 | #endif |
| 26 | |
| 27 | -#ifdef __linux__ |
| 28 | -# include <sys/syscall.h> |
| 29 | -#endif |
| 30 | - |
| 31 | #include <stdio.h> |
| 32 | #include <assert.h> |
| 33 | #include <setjmp.h> |
| 34 | @@ -2895,7 +2891,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) |
| 35 | struct dirent *next; |
| 36 | uintmax_t total_blocks = 0; |
| 37 | static bool first = true; |
| 38 | - bool found_any_entries = false; |
| 39 | |
| 40 | errno = 0; |
| 41 | dirp = opendir (name); |
| 42 | @@ -2971,7 +2966,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) |
| 43 | next = readdir (dirp); |
| 44 | if (next) |
| 45 | { |
| 46 | - found_any_entries = true; |
| 47 | if (! file_ignored (next->d_name)) |
| 48 | { |
| 49 | enum filetype type = unknown; |
| 50 | @@ -3017,22 +3011,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) |
| 51 | if (errno != EOVERFLOW) |
| 52 | break; |
| 53 | } |
| 54 | -#ifdef __linux__ |
| 55 | - else if (! found_any_entries) |
| 56 | - { |
| 57 | - /* If readdir finds no directory entries at all, not even "." or |
| 58 | - "..", then double check that the directory exists. */ |
| 59 | - if (syscall (SYS_getdents, dirfd (dirp), NULL, 0) == -1 |
| 60 | - && errno != EINVAL) |
| 61 | - { |
| 62 | - /* We exclude EINVAL as that pertains to buffer handling, |
| 63 | - and we've passed NULL as the buffer for simplicity. |
| 64 | - ENOENT is returned if appropriate before buffer handling. */ |
| 65 | - file_failure (command_line_arg, _("reading directory %s"), name); |
| 66 | - } |
| 67 | - break; |
| 68 | - } |
| 69 | -#endif |
| 70 | else |
| 71 | break; |
| 72 | |
| 73 | diff --git a/tests/ls/removed-directory.sh b/tests/ls/removed-directory.sh |
| 74 | index e8c835d..fe8f929 100755 |
| 75 | --- a/tests/ls/removed-directory.sh |
| 76 | +++ b/tests/ls/removed-directory.sh |
| 77 | @@ -26,20 +26,14 @@ case $host_triplet in |
| 78 | *) skip_ 'non linux kernel' ;; |
| 79 | esac |
| 80 | |
| 81 | -LS_FAILURE=2 |
| 82 | - |
| 83 | -cat <<\EOF >exp-err || framework_failure_ |
| 84 | -ls: reading directory '.': No such file or directory |
| 85 | -EOF |
| 86 | - |
| 87 | cwd=$(pwd) |
| 88 | mkdir d || framework_failure_ |
| 89 | cd d || framework_failure_ |
| 90 | rmdir ../d || framework_failure_ |
| 91 | |
| 92 | -returns_ $LS_FAILURE ls >../out 2>../err || fail=1 |
| 93 | +ls >../out 2>../err || fail=1 |
| 94 | cd "$cwd" || framework_failure_ |
| 95 | compare /dev/null out || fail=1 |
| 96 | -compare exp-err err || fail=1 |
| 97 | +compare /dev/null err || fail=1 |
| 98 | |
| 99 | Exit $fail |