From 28738a3b22d4c70bf6187c829fede5d711177953 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Sat, 27 Jan 2018 00:02:16 +0300
Subject: [PATCH] find: make -delete honour ignore_readdir_race

Make -delete action not to fail if the file already removed by the time
find tries to unlink it if -ignore_readdir_race is supplied. Document
the changes as well.
---
 find/find.1 | 14 ++++++++------
 find/pred.c |  4 ++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/find/find.1 b/find/find.1
index e376ab6c..c66656d6 100644
--- a/find/find.1
+++ b/find/find.1
@@ -476,12 +476,14 @@ and exit.
 Normally, \fBfind\fR will emit an error message when it fails to stat a file.
 If you give this option and a file is deleted between the time \fBfind\fR
 reads the name of the file from the directory and the time it tries to stat
-the file, no error message will be issued.    This also applies to files
-or directories whose names are given on the command line.  This option takes
-effect at the time the command line is read, which means that you cannot search
-one part of the filesystem with 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).
+the file, no error message will be issued. The same applies to the
+\fB-delete\fR action, if file already removed by the time \fBfind\fR tries to
+unlink it, no errors would be issued and \fB-delete\fR will return true.  This
+also applies to files or directories whose names are given on the command
+line.  This option takes effect at the time the command line is read, which
+means that you cannot search one part of the filesystem with 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).
 
 .IP "\-maxdepth \fIlevels\fR"
 Descend at most \fIlevels\fR (a non-negative integer) levels of
diff --git a/find/pred.c b/find/pred.c
index 7e2a7bde..ae3baf5b 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -326,6 +326,10 @@ pred_delete (const char *pathname, struct stat *stat_buf, struct predicate *pred
 		    return true;
 		}
 	    }
+          if (ENOENT == errno && options.ignore_readdir_race)
+            {
+              return true;
+            }
 	}
       error (0, errno, _("cannot delete %s"),
 	     safely_quote_err_filename (0, pathname));
-- 
2.13.6

