Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b22ff7

Browse files
committed
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 085b6b6 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/[email protected]
1 parent fade4d4 commit 5b22ff7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/backend/utils/adt/genfile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,14 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir)
581581
/* Get the file info */
582582
snprintf(path, sizeof(path), "%s/%s", dir, de->d_name);
583583
if (stat(path, &attrib) < 0)
584+
{
585+
/* Ignore concurrently-deleted files, else complain */
586+
if (errno == ENOENT)
587+
continue;
584588
ereport(ERROR,
585589
(errcode_for_file_access(),
586590
errmsg("could not stat file \"%s\": %m", path)));
591+
}
587592

588593
/* Ignore anything but regular files */
589594
if (!S_ISREG(attrib.st_mode))

0 commit comments

Comments
 (0)