Commit | Line | Data |
---|---|---|
b8111d56 VM |
1 | From 10fcb97bd728f09d4a027eddf8ad2900f0819b0a 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 | NEWS | 6 ++++++ | |
13 | src/ls.c | 22 ---------------------- | |
14 | tests/ls/removed-directory.sh | 10 ++-------- | |
15 | 3 files changed, 8 insertions(+), 30 deletions(-) | |
16 | ||
17 | diff --git a/NEWS b/NEWS | |
18 | index fdc8bf5db..653e7178b 100644 | |
19 | --- a/NEWS | |
20 | +++ b/NEWS | |
21 | @@ -2,6 +2,12 @@ GNU coreutils NEWS -*- outline -*- | |
22 | ||
23 | * Noteworthy changes in release ?.? (????-??-??) [?] | |
24 | ||
25 | +** Changes in behavior | |
26 | + | |
27 | + On GNU/Linux systems, ls no longer issues an error message on | |
28 | + directory merely because it was removed. This reverts a change | |
29 | + that was made in release 8.32. | |
30 | + | |
31 | ||
32 | * Noteworthy changes in release 8.32 (2020-03-05) [stable] | |
33 | ||
34 | diff --git a/src/ls.c b/src/ls.c | |
35 | index 24b983287..4acf5f44d 100644 | |
36 | --- a/src/ls.c | |
37 | +++ b/src/ls.c | |
38 | @@ -49,10 +49,6 @@ | |
39 | # include <sys/ptem.h> | |
40 | #endif | |
41 | ||
42 | -#ifdef __linux__ | |
43 | -# include <sys/syscall.h> | |
44 | -#endif | |
45 | - | |
46 | #include <stdio.h> | |
47 | #include <assert.h> | |
48 | #include <setjmp.h> | |
49 | @@ -2896,7 +2892,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) | |
50 | struct dirent *next; | |
51 | uintmax_t total_blocks = 0; | |
52 | static bool first = true; | |
53 | - bool found_any_entries = false; | |
54 | ||
55 | errno = 0; | |
56 | dirp = opendir (name); | |
57 | @@ -2972,7 +2967,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) | |
58 | next = readdir (dirp); | |
59 | if (next) | |
60 | { | |
61 | - found_any_entries = true; | |
62 | if (! file_ignored (next->d_name)) | |
63 | { | |
64 | enum filetype type = unknown; | |
65 | @@ -3018,22 +3012,6 @@ print_dir (char const *name, char const *realname, bool command_line_arg) | |
66 | if (errno != EOVERFLOW) | |
67 | break; | |
68 | } | |
69 | -#ifdef __linux__ | |
70 | - else if (! found_any_entries) | |
71 | - { | |
72 | - /* If readdir finds no directory entries at all, not even "." or | |
73 | - "..", then double check that the directory exists. */ | |
74 | - if (syscall (SYS_getdents, dirfd (dirp), NULL, 0) == -1 | |
75 | - && errno != EINVAL) | |
76 | - { | |
77 | - /* We exclude EINVAL as that pertains to buffer handling, | |
78 | - and we've passed NULL as the buffer for simplicity. | |
79 | - ENOENT is returned if appropriate before buffer handling. */ | |
80 | - file_failure (command_line_arg, _("reading directory %s"), name); | |
81 | - } | |
82 | - break; | |
83 | - } | |
84 | -#endif | |
85 | else | |
86 | break; | |
87 | ||
88 | diff --git a/tests/ls/removed-directory.sh b/tests/ls/removed-directory.sh | |
89 | index e8c835dab..fe8f929a1 100755 | |
90 | --- a/tests/ls/removed-directory.sh | |
91 | +++ b/tests/ls/removed-directory.sh | |
92 | @@ -26,20 +26,14 @@ case $host_triplet in | |
93 | *) skip_ 'non linux kernel' ;; | |
94 | esac | |
95 | ||
96 | -LS_FAILURE=2 | |
97 | - | |
98 | -cat <<\EOF >exp-err || framework_failure_ | |
99 | -ls: reading directory '.': No such file or directory | |
100 | -EOF | |
101 | - | |
102 | cwd=$(pwd) | |
103 | mkdir d || framework_failure_ | |
104 | cd d || framework_failure_ | |
105 | rmdir ../d || framework_failure_ | |
106 | ||
107 | -returns_ $LS_FAILURE ls >../out 2>../err || fail=1 | |
108 | +ls >../out 2>../err || fail=1 | |
109 | cd "$cwd" || framework_failure_ | |
110 | compare /dev/null out || fail=1 | |
111 | -compare exp-err err || fail=1 | |
112 | +compare /dev/null err || fail=1 | |
113 | ||
114 | Exit $fail |