]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
rm -f: ignore EROFS when it's really ENOENT
authorJim Meyering <meyering@redhat.com>
Tue, 3 Nov 2009 11:01:40 +0000 (12:01 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 3 Nov 2009 13:14:00 +0000 (14:14 +0100)
rm -f must not print a diagnostic for a nonexistent file.  However,
most linux-based kernel unlinkat functions set errno to EROFS when
the named file (regardless of whether it exists) would lie on a
read-only file system.  remove.c now performs an extra fstatat call
in that case, to determine whether the file exists.
* src/remove.c (excise): Map EROFS to ENOENT, if a file is nonexistent.
Reported by Steven Drake in <http://savannah.gnu.org/bugs/?27923>.
* NEWS (Changes in behavior): Mention it.

NEWS
THANKS
src/remove.c

diff --git a/NEWS b/NEWS
index 0760775256fad710b80d64efb43e29946a354817..03ed83ff3f1d8dac4c50a0fc37e2e7a7232356de 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,12 @@ GNU coreutils NEWS                                    -*- outline -*-
 
   echo and printf now interpret \e as the Escape character (0x1B).
 
+  rm -f /read-only-fs/nonexistent now succeeds and prints no diagnostic
+  on systems with an unlinkat syscall that sets errno to EROFS in that case.
+  Before, it would fail with a "Read-only file system" diagnostic.
+  Also, "rm /read-only-fs/nonexistent" now reports "file not found" rather
+  than the less precise "Read-only file system" error.
+
 ** New features
 
   env and printenv now accept the option --null (-0), as a means to
diff --git a/THANKS b/THANKS
index 5efe2fa1e98f1921d39aa83371f861faf8efe2dc..c583e2af5af23595089a1daaa4f54ab36313676b 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -541,6 +541,7 @@ Stephen Smoogen                     smooge@mindspring.com
 Steve McConnel                      steve@acadcomp.sil.org
 Steve McIntyre                      steve@einval.com
 Steve Ward                          planet36@gmail.com
+Steven Drake                        sbd@users.sourceforge.net
 Steven G. Johnson                   stevenj@alum.mit.edu
 Steven Mocking                      ufo@quicknet.nl
 Steven Parkes                       smparkes@smparkes.net
index 87fb32bf9cdfbc27c7828852f97d2b4a085ee85c..c4b93fe7e032c6cb873262d0a38744c81c1e2b58 100644 (file)
@@ -437,6 +437,18 @@ excise (FTS *fts, FTSENT *ent, struct rm_options const *x, bool is_dir)
       return RM_OK;
     }
 
+  /* The unlinkat from kernels like linux-2.6.32 reports EROFS even for
+     nonexistent files.  When the file is indeed missing, map that to ENOENT,
+     so that rm -f ignores it, as required.  Even without -f, this is useful
+     because it makes rm print the more precise diagnostic.  */
+  if (errno == EROFS)
+    {
+      struct stat st;
+      if ( ! (lstatat (fts->fts_cwd_fd, ent->fts_accpath, &st)
+                       && errno == ENOENT))
+        errno = EROFS;
+    }
+
   if (ignorable_missing (x, errno))
     return RM_OK;