diff options
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r-- | src/backend/storage/file/fd.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 8917c6004ac..43d2b2a156e 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -494,6 +494,29 @@ retry: } /* + * pg_file_exists -- check that a file exists. + * + * This requires an absolute path to the file. Returns true if the file is + * not a directory, false otherwise. + */ +bool +pg_file_exists(const char *name) +{ + struct stat st; + + Assert(name != NULL); + + if (stat(name, &st) == 0) + return !S_ISDIR(st.st_mode); + else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES)) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not access file \"%s\": %m", name))); + + return false; +} + +/* * pg_flush_data --- advise OS that the described dirty data should be flushed * * offset of 0 with nbytes 0 means that the entire file should be flushed |