aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-03-31 12:57:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-03-31 12:57:55 -0400
commitee40e8975e2cd2811d14a35ce9179bd46e1f59f2 (patch)
tree7e23d148d66a94e3d333cd5c0145126a37314357
parent94c9152dc880a8b1d1223c885d6d56d33e417b57 (diff)
downloadpostgresql-ee40e8975e2cd2811d14a35ce9179bd46e1f59f2.tar.gz
postgresql-ee40e8975e2cd2811d14a35ce9179bd46e1f59f2.zip
Teach pg_ls_dir_files() to ignore ENOENT failures from stat().
Buildfarm experience shows that this function can fail with ENOENT if some other process unlinks a file between when we read the directory entry and when we try to stat() it. The problem is old but we had not noticed it until 085b6b667 added regression test coverage. To fix, just ignore ENOENT failures. There is one other case that this might hide: a symlink that points to nowhere. That seems okay though, at least better than erroring. Back-patch to v10 where this function was added, since the regression test cases were too. Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com
-rw-r--r--src/backend/utils/adt/genfile.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index cf54f4be230..3a550a12bff 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -596,9 +596,14 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir, bool missing_ok)
/* Get the file info */
snprintf(path, sizeof(path), "%s/%s", dir, de->d_name);
if (stat(path, &attrib) < 0)
+ {
+ /* Ignore concurrently-deleted files, else complain */
+ if (errno == ENOENT)
+ continue;
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not stat file \"%s\": %m", path)));
+ }
/* Ignore anything but regular files */
if (!S_ISREG(attrib.st_mode))