bin/90687: [patch] side effect of -delete option of find(1)
anatoli at aksoft.net
Tue Dec 20 07:00:15 PST 2005
>Synopsis: [patch] side effect of -delete option of find(1)
>Arrival-Date: Tue Dec 20 15:00:12 GMT 2005
>Originator: Anatoli Klassen
>Release: FreeBSD 5.4-RELEASE-p6 i386
System: FreeBSD mercury.26th.net 5.4-RELEASE-p6 FreeBSD 5.4-RELEASE-p6 #0: Wed Jul 27 12:58:07 CEST 2005 root at mercury.26th.net:/usr/obj/usr/src/sys/MERCURY i386
If -delete option is used it cancel -L option silently.
So find does something different as it does with just -print option.
The result could be deleting of all symbolic links instead of broken ones only even
if user has already validated this with previous -print run.
Create a file, symbolic link to it and a broken symbolic link:
touch a && ln -s a b && ln -s c d
Now detect all broken links:
find -L . -type l
- works fine, shows that "d" is broken.
Then try to delete the broken links
find -L . -type l -delete
- all links are deleted, not only broken ones.
A patch to remove the side effect. It does not allow to delete the broken links because
there is once more check in the code with comment "sanity check", but at least it will
show error message and not delete correct links.
--- /usr/src/usr.bin/find/function.c Thu Jul 29 05:33:55 2004
+++ find/function.c Tue Dec 20 14:16:56 2005
@@ -453,8 +453,6 @@
ftsoptions &= ~FTS_NOSTAT; /* no optimise */
- ftsoptions |= FTS_PHYSICAL; /* disable -follow */
- ftsoptions &= ~FTS_LOGICAL; /* disable -follow */
isoutput = 1; /* possible output */
isdepth = 1; /* -depth implied */
To delete the links really one can use "find -L . -type l -print0 | xargs -0 rm"
More information about the freebsd-bugs