bin/187264: rm command: rm -r file1 file2 "" does not remove existing files or directories
Jilles Tjoelker
jilles at stack.nl
Tue Mar 4 23:30:02 UTC 2014
The following reply was made to PR bin/187264; it has been noted by GNATS.
From: Jilles Tjoelker <jilles at stack.nl>
To: bug-followup at FreeBSD.org, jlw at xinuos.com
Cc:
Subject: Re: bin/187264: rm command: rm -r file1 file2 "" does not
remove existing files or directories
Date: Wed, 5 Mar 2014 00:23:15 +0100
In PR bin/187264, you wrote:
> When the gmake/make clean target contains a command of the form
> rm -rf "a.out" "$(DSYM)" main.o main.d
> the command fails to remove any of the existing files if DSYM is null.
> The '-f' option hides the error associated with the zero length file
> name, but gives no indication that, in fact, NO files/directories have
> been removed.
I can reproduce this, not only with rm, but also with ls, cp and find.
The underlying fts_open(3) fails if any pathname is empty and causes the
entire command to fail. If a pathname otherwise does not refer to an
existing file, this correctly does not prevent processing of other
pathnames.
The below patch makes fts_open(3) treat an empty pathname like any other
pathname that cannot be lstatted because of [ENOENT]. It is lightly
tested.
Index: lib/libc/gen/fts.c
===================================================================
--- lib/libc/gen/fts.c (revision 262358)
+++ lib/libc/gen/fts.c (working copy)
@@ -161,11 +161,7 @@ fts_open(argv, options, compar)
/* Allocate/initialize root(s). */
for (root = NULL, nitems = 0; *argv != NULL; ++argv, ++nitems) {
- /* Don't allow zero-length paths. */
- if ((len = strlen(*argv)) == 0) {
- errno = ENOENT;
- goto mem3;
- }
+ len = strlen(*argv);
p = fts_alloc(sp, *argv, len);
p->fts_level = FTS_ROOTLEVEL;
--
Jilles Tjoelker
More information about the freebsd-bugs
mailing list