0001-ls-restore-8.31-behavior-on-removed-directories.patch 3.5 KB

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