Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite72a375

Browse files
committed
Refactor code checking for file existence
jit.c and dfgr.c had a copy of the same code to check if a file existsor not, with a twist: jit.c did not check for EACCES when failing thestat() call for the path whose existence is tested. This refactoredroutine will be used by an upcoming patch.Reviewed-by: Ashutosh BapatDiscussion:https://postgr.es/m/ZTiV8tn_MIb_H2rE@paquier.xyz
1 parent08c3ad2 commite72a375

File tree

4 files changed

+29
-40
lines changed

4 files changed

+29
-40
lines changed

‎src/backend/jit/jit.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ static bool provider_failed_loading = false;
4545

4646

4747
staticboolprovider_init(void);
48-
staticboolfile_exists(constchar*name);
4948

5049

5150
/*
@@ -89,7 +88,7 @@ provider_init(void)
8988
*/
9089
snprintf(path,MAXPGPATH,"%s/%s%s",pkglib_path,jit_provider,DLSUFFIX);
9190
elog(DEBUG1,"probing availability of JIT provider at %s",path);
92-
if (!file_exists(path))
91+
if (!pg_file_exists(path))
9392
{
9493
elog(DEBUG1,
9594
"provider not available, disabling JIT for current session");
@@ -188,20 +187,3 @@ InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add)
188187
INSTR_TIME_ADD(dst->optimization_counter,add->optimization_counter);
189188
INSTR_TIME_ADD(dst->emission_counter,add->emission_counter);
190189
}
191-
192-
staticbool
193-
file_exists(constchar*name)
194-
{
195-
structstatst;
196-
197-
Assert(name!=NULL);
198-
199-
if (stat(name,&st)==0)
200-
return !S_ISDIR(st.st_mode);
201-
elseif (!(errno==ENOENT||errno==ENOTDIR))
202-
ereport(ERROR,
203-
(errcode_for_file_access(),
204-
errmsg("could not access file \"%s\": %m",name)));
205-
206-
return false;
207-
}

‎src/backend/storage/file/fd.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,29 @@ pg_fdatasync(int fd)
493493
returnrc;
494494
}
495495

496+
/*
497+
* pg_file_exists -- check that a file exists.
498+
*
499+
* This requires an absolute path to the file. Returns true if the file is
500+
* not a directory, false otherwise.
501+
*/
502+
bool
503+
pg_file_exists(constchar*name)
504+
{
505+
structstatst;
506+
507+
Assert(name!=NULL);
508+
509+
if (stat(name,&st)==0)
510+
return !S_ISDIR(st.st_mode);
511+
elseif (!(errno==ENOENT||errno==ENOTDIR||errno==EACCES))
512+
ereport(ERROR,
513+
(errcode_for_file_access(),
514+
errmsg("could not access file \"%s\": %m",name)));
515+
516+
return false;
517+
}
518+
496519
/*
497520
* pg_flush_data --- advise OS that the described dirty data should be flushed
498521
*

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include"fmgr.h"
3434
#include"lib/stringinfo.h"
3535
#include"miscadmin.h"
36+
#include"storage/fd.h"
3637
#include"storage/shmem.h"
3738
#include"utils/hsearch.h"
3839

@@ -78,7 +79,6 @@ char *Dynamic_library_path;
7879
staticvoid*internal_load_library(constchar*libname);
7980
staticvoidincompatible_module_error(constchar*libname,
8081
constPg_magic_struct*module_magic_data)pg_attribute_noreturn();
81-
staticboolfile_exists(constchar*name);
8282
staticchar*expand_dynamic_library_name(constchar*name);
8383
staticvoidcheck_restricted_library_name(constchar*name);
8484
staticchar*substitute_libpath_macro(constchar*name);
@@ -400,23 +400,6 @@ incompatible_module_error(const char *libname,
400400
errdetail_internal("%s",details.data)));
401401
}
402402

403-
staticbool
404-
file_exists(constchar*name)
405-
{
406-
structstatst;
407-
408-
Assert(name!=NULL);
409-
410-
if (stat(name,&st)==0)
411-
return !S_ISDIR(st.st_mode);
412-
elseif (!(errno==ENOENT||errno==ENOTDIR||errno==EACCES))
413-
ereport(ERROR,
414-
(errcode_for_file_access(),
415-
errmsg("could not access file \"%s\": %m",name)));
416-
417-
return false;
418-
}
419-
420403

421404
/*
422405
* If name contains a slash, check if the file exists, if so return
@@ -447,7 +430,7 @@ expand_dynamic_library_name(const char *name)
447430
else
448431
{
449432
full=substitute_libpath_macro(name);
450-
if (file_exists(full))
433+
if (pg_file_exists(full))
451434
returnfull;
452435
pfree(full);
453436
}
@@ -465,7 +448,7 @@ expand_dynamic_library_name(const char *name)
465448
{
466449
full=substitute_libpath_macro(new);
467450
pfree(new);
468-
if (file_exists(full))
451+
if (pg_file_exists(full))
469452
returnfull;
470453
pfree(full);
471454
}
@@ -582,7 +565,7 @@ find_in_dynamic_libpath(const char *basename)
582565

583566
elog(DEBUG3,"find_in_dynamic_libpath: trying \"%s\"",full);
584567

585-
if (file_exists(full))
568+
if (pg_file_exists(full))
586569
returnfull;
587570

588571
pfree(full);

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ extern intpg_fsync(int fd);
182182
externintpg_fsync_no_writethrough(intfd);
183183
externintpg_fsync_writethrough(intfd);
184184
externintpg_fdatasync(intfd);
185+
externboolpg_file_exists(constchar*fname);
185186
externvoidpg_flush_data(intfd,off_toffset,off_tnbytes);
186187
externintpg_truncate(constchar*path,off_tlength);
187188
externvoidfsync_fname(constchar*fname,boolisdir);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp