postgres.git / summary / log / commit / refs

commit    5b22ff764b0f60c24d89ec0180476cda361ec126
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Tue Mar 31 16:57:55 2020 +0000
First released in: 13.0, 10.13, 11.8, 12.3

    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


src/backend/utils/adt/genfile.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c index 2a03385e109..7c1e81e4504 100644 --- a/src/backend/utils/adt/genfile.c +++ b/src/backend/utils/adt/genfile.c @@ -581,9 +581,14 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir) /* 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)) [parent: fade4d4dffca]