mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +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:
@@ -45,7 +45,6 @@ static bool provider_failed_loading = false;
|
||||
|
||||
|
||||
static bool provider_init(void);
|
||||
static bool file_exists(const char *name);
|
||||
|
||||
|
||||
/*
|
||||
@@ -89,7 +88,7 @@ provider_init(void)
|
||||
*/
|
||||
snprintf(path, MAXPGPATH, "%s/%s%s", pkglib_path, jit_provider, DLSUFFIX);
|
||||
elog(DEBUG1, "probing availability of JIT provider at %s", path);
|
||||
if (!file_exists(path))
|
||||
if (!pg_file_exists(path))
|
||||
{
|
||||
elog(DEBUG1,
|
||||
"provider not available, disabling JIT for current session");
|
||||
@@ -188,20 +187,3 @@ InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add)
|
||||
INSTR_TIME_ADD(dst->optimization_counter, add->optimization_counter);
|
||||
INSTR_TIME_ADD(dst->emission_counter, add->emission_counter);
|
||||
}
|
||||
|
||||
static bool
|
||||
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))
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not access file \"%s\": %m", name)));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user