mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Refactor code checking for file existence
jit.c and dfgr.c had a copy of the same code to check if a file exists or not, with a twist: jit.c did not check for EACCES when failing the stat() call for the path whose existence is tested. This refactored routine will be used by an upcoming patch. Reviewed-by: Ashutosh Bapat Discussion: https://postgr.es/m/ZTiV8tn_MIb_H2rE@paquier.xyz
This commit is contained in:
@ -493,6 +493,29 @@ retry:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
|
Reference in New Issue
Block a user