[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug #17900] rm -f should ignore ENOTDIR
From: |
Jim Meyering |
Subject: |
Re: [bug #17900] rm -f should ignore ENOTDIR |
Date: |
Mon, 02 Oct 2006 19:19:04 +0200 |
Andreas Schwab <address@hidden> wrote:
> <http://savannah.gnu.org/bugs/?17900>
> Details:
>
> $ touch x
> $ rm -f x/y; echo $?
> rm: cannot remove `x/y': Not a directory
> 1
>
> This error should be ignored. After all, if a file name component is not a
> directory the file cannot exist, so rm -f should handle it the same as
> ENOENT.
Hi Andreas,
Thanks for reporting that.
Here's the patch I'll check in as soon as I write the test cases:
2006-10-02 Jim Meyering <address@hidden>
With --force (-f), rm no longer fails for ENOTDIR.
* src/remove.c (ignorable_missing): New function.
Use it everywhere, rather than open-coding the test.
Reported by Andreas Schwab.
Index: src/remove.c
===================================================================
RCS file: /fetish/cu/src/remove.c,v
retrieving revision 1.162
diff -u -r1.162 remove.c
--- src/remove.c 29 Sep 2006 15:58:05 -0000 1.162
+++ src/remove.c 2 Oct 2006 17:14:43 -0000
@@ -899,7 +899,7 @@
return RM_OK; \
} \
\
- if (errno == ENOENT && (X)->ignore_missing_files)
\
+ if (ignorable_missing (X, errno))
\
return RM_OK; \
} \
while (0)
@@ -915,7 +915,7 @@
return RM_OK; \
} \
\
- if (errno == ENOENT && (X)->ignore_missing_files) \
+ if (ignorable_missing (X, errno)) \
return RM_OK; \
\
if (errno == ENOTEMPTY || errno == EEXIST) \
@@ -923,6 +923,14 @@
} \
while (0)
+/* Encapsulate the test for whether the errno value, ERRNUM, is ignorable. */
+static inline bool
+ignorable_missing (struct rm_options const *x, int errnum)
+{
+ return (x->ignore_missing_files
+ && (errnum == ENOENT || errnum == ENOTDIR));
+}
+
/* Remove the file or directory specified by FILENAME.
Return RM_OK if it is removed, and RM_ERROR or RM_USER_DECLINED if not.
But if FILENAME specifies a non-empty directory, return RM_NONEMPTY_DIR. */
@@ -1014,7 +1022,7 @@
{
if (fstatat (fd_cwd, filename, st, AT_SYMLINK_NOFOLLOW))
{
- if (errno == ENOENT && x->ignore_missing_files)
+ if (ignorable_missing (x, errno))
return RM_OK;
error (0, errno, _("cannot remove %s"),
@@ -1195,7 +1203,7 @@
/* CAUTION: this test and diagnostic are identical to
those following the other use of fd_to_subdirp. */
- if (errno == ENOENT && x->ignore_missing_files)
+ if (ignorable_missing (x, errno))
{
/* With -f, don't report "file not found". */
}
@@ -1281,7 +1289,7 @@
{
/* CAUTION: this test and diagnostic are identical to
those following the other use of fd_to_subdirp. */
- if (errno == ENOENT && x->ignore_missing_files)
+ if (ignorable_missing (x, errno))
{
/* With -f, don't report "file not found". */
}
@@ -1426,7 +1434,7 @@
{
if (cache_fstatat (AT_FDCWD, filename, &st, AT_SYMLINK_NOFOLLOW) != 0)
{
- if (errno == ENOENT && x->ignore_missing_files)
+ if (ignorable_missing (x, errno))
return RM_OK;
error (0, errno, _("cannot remove %s"), quote (filename));
return RM_ERROR;
- [bug #17900] rm -f should ignore ENOTDIR, Andreas Schwab, 2006/10/02
- Re: [bug #17900] rm -f should ignore ENOTDIR,
Jim Meyering <=
- Re: [bug #17900] rm -f should ignore ENOTDIR, Eric Blake, 2006/10/02
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Paul Eggert, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Paul Eggert, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Jim Meyering, 2006/10/03
- Re: [bug #17900] rm -f should ignore ENOTDIR, Eric Blake, 2006/10/03