summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2018-01-30 23:30:09 +0100
committerBernhard Voelker <mail@bernhard-voelker.de>2018-03-14 20:44:14 +0100
commit0afb2efada7e435ae18ef7d3db0758464189f44f (patch)
tree24362706c216ccd389d7e301e91e00c1363746e6
parent2d6ce760f1ad75f672024250127e6afaa7345bb3 (diff)
downloadfindutils-0afb2efad.tar.gz
find: make -delete honour the -ignore_readdir_race option
* find/pred.c (pred_delete): Return true when the -ignore_readdir_race option is active and unlinkat() came back with ENOENT. * doc/find.texi (Option -ignore_readdir_race): Document the change. (Action -delete): Likewise. * find/find.1: Likewise. * NEWS (Bug Fixes): Mention the fix. For now, it seems a bit hard to add a proper test for this, so the following shell snippet demonstrates the race: $ seq 10 | xargs touch $ env time -f 'find exit status: %x\nfind time: %e' \ find -ignore_readdir_race -type f \ -delete \ -exec sh -c 'sleep $(basename {})' \; \ -printf 'find deleted: %p\n' \ & \ sleep 20; \ seq 10 | xargs rm -fv; \ wait $! Reported by Alexander Golubev in https://savannah.gnu.org/bugs/?52981
-rw-r--r--NEWS4
-rw-r--r--doc/find.texi15
-rw-r--r--find/find.122
-rw-r--r--find/pred.c6
4 files changed, 46 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 88cf17d..9809bf4 100644
--- a/NEWS
+++ b/NEWS
@@ -54,6 +54,10 @@ Some minor documentation improvements are listed in "Bug Fixes" below.
** Bug Fixes
+#52981: find: the '-delete' action no longer complains about disappeared files
+ when the '-ignore_readdir_race' option is given, too. That action will
+ also returns true in such a case now.
+
#52220: 'find -D' without any further argument no longer crashes.
Bug present since the implementation of -D in FINDUTILS_4_3_1-1.
diff --git a/doc/find.texi b/doc/find.texi
index 3580be7..0089193 100644
--- a/doc/find.texi
+++ b/doc/find.texi
@@ -1424,7 +1424,15 @@ gives a significant increase in search speed.
If a file disappears after its name has been read from a directory but
before @code{find} gets around to examining the file with @code{stat},
don't issue an error message. If you don't specify this option, an
-error message will be issued. This option can be useful in system
+error message will be issued.
+
+Furthermore, @code{find} with the @samp{-ignore_readdir_race} option
+will ignore errors of the @samp{-delete} action in the case the file
+has disappeared since the parent directory was read: it will not output
+an error diagnostic, and the return code of the @samp{-delete} action
+will be true.
+
+This option can be useful in system
scripts (cron scripts, for example) that examine areas of the
filesystem that change frequently (mail queues, temporary directories,
and so forth), because this scenario is common for those sorts of
@@ -2787,6 +2795,11 @@ explicitly.
If @samp{-delete} fails, @code{find}'s exit status will be nonzero
(when it eventually exits).
+
+Together with the @samp{-ignore_readdir_race} option, @code{find} will
+ignore errors of the @samp{-delete} action in the case the file has disappeared
+since the parent directory was read: it will not output an error diagnostic, and
+the return code of the @samp{-delete} action will be true.
@end deffn
@node Adding Tests
diff --git a/find/find.1 b/find/find.1
index 0437cd8..0d44c37 100644
--- a/find/find.1
+++ b/find/find.1
@@ -495,6 +495,17 @@ this option on and part of it with this option off
(if you need to do that, you will need to issue two \fBfind\fR commands
instead, one with the option and one without it).
+Furthermore,
+.B find
+with the
+.B \-ignore_readdir_race
+option will ignore errors of the
+.B \-delete
+action in the case the file has disappeared since the parent directory was read:
+it will not output an error diagnostic, and the return code of the
+.B \-delete
+action will be true.
+
.IP "\-maxdepth \fIlevels\fR"
Descend at most \fIlevels\fR (a non-negative integer) levels of
directories below the starting-points.
@@ -1087,6 +1098,17 @@ and
.B \-delete
together.
+Together with the
+.B \-ignore_readdir_race
+option,
+.B find
+will ignore errors of the
+.B \-delete
+action in the case the file has disappeared since the parent directory was
+read: it will not output an error diagnostic, and the return code of the
+.B \-delete
+action will be true.
+
.IP "\-exec \fIcommand\fR ;"
Execute
.IR command ;
diff --git a/find/pred.c b/find/pred.c
index 7e2a7bd..af3bacb 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -316,6 +316,12 @@ pred_delete (const char *pathname, struct stat *stat_buf, struct predicate *pred
}
else
{
+ if (ENOENT == errno && options.ignore_readdir_race)
+ {
+ /* Ignore unlink() error for vanished files. */
+ errno = 0;
+ return true;
+ }
if (EISDIR == errno)
{
if ((flags & AT_REMOVEDIR) == 0)