91 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
92 errmsg(
"reference to parent directory (\"..\") not allowed")));
97 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
98 errmsg(
"absolute path not allowed")));
102 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
103 errmsg(
"path must be in or below the current directory")));
117 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
118 errmsg(
"only superuser may access generic file functions")));
185 if (
stat(filename, &fst) >= 0)
187 (
errcode(ERRCODE_DUPLICATE_FILE),
188 errmsg(
"file \"%s\" exists", filename)));
198 errmsg(
"could not open file \"%s\" for writing: %m",
205 errmsg(
"could not write file \"%s\": %m", filename)));
224 if (
stat(filename, &fst) < 0)
227 errmsg(
"could not stat file \"%s\": %m", filename)));
321 if (access(fn1, W_OK) < 0)
325 errmsg(
"file \"%s\" is not accessible: %m", fn1)));
330 if (fn3 && access(fn2, W_OK) < 0)
334 errmsg(
"file \"%s\" is not accessible: %m", fn2)));
339 rc = access(fn3 ? fn3 : fn2, W_OK);
340 if (rc >= 0 || errno != ENOENT)
343 (
errcode(ERRCODE_DUPLICATE_FILE),
344 errmsg(
"cannot rename to target file \"%s\"",
350 if (rename(fn2, fn3) != 0)
354 errmsg(
"could not rename \"%s\" to \"%s\": %m",
357 if (rename(fn1, fn2) != 0)
361 errmsg(
"could not rename \"%s\" to \"%s\": %m",
364 if (rename(fn3, fn2) != 0)
368 errmsg(
"could not rename \"%s\" back to \"%s\": %m",
374 (
errcode(ERRCODE_UNDEFINED_FILE),
375 errmsg(
"renaming \"%s\" to \"%s\" was reverted",
380 else if (rename(fn1, fn2) != 0)
384 errmsg(
"could not rename \"%s\" to \"%s\": %m", fn1, fn2)));
407 if (access(filename, W_OK) < 0)
414 errmsg(
"file \"%s\" is not accessible: %m", filename)));
417 if (unlink(filename) < 0)
421 errmsg(
"could not unlink file \"%s\": %m", filename)));
445 if (access(filename, W_OK) < 0)
452 errmsg(
"file \"%s\" is not accessible: %m", filename)));
455 if (unlink(filename) < 0)
459 errmsg(
"could not unlink file \"%s\": %m", filename)));
478 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
479 errmsg(
"only superuser can list the log directory")));
511 if (strcmp(
Log_filename,
"postgresql-%Y-%m-%d_%H%M%S.log") != 0)
513 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
514 errmsg(
"the log_filename parameter must equal 'postgresql-%%Y-%%m-%%d_%%H%%M%%S.log'")));
519 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
520 errmsg(
"set-valued function called in context that cannot accept a set")));
523 (
errcode(ERRCODE_SYNTAX_ERROR),
524 errmsg(
"materialize mode required, but it is not allowed in this context")));
531 TIMESTAMPOID, -1, 0);
550 char timestampbuf[32];
563 if (strlen(de->d_name) != 32
564 || strncmp(de->d_name,
"postgresql-", 11) != 0
565 || de->d_name[21] !=
'_' 566 || strcmp(de->d_name + 28,
".log") != 0)
570 strcpy(timestampbuf, de->d_name + 11);
571 timestampbuf[17] =
'\0';
582 values[0] = timestampbuf;
static char * convert_and_check_filename(text *arg)
Datum pg_file_write(PG_FUNCTION_ARGS)
static bool pg_file_rename_internal(text *file1, text *file2, text *file3)
#define IsA(nodeptr, _type_)
TupleDesc CreateTemplateTupleDesc(int natts)
Datum pg_file_write_v1_1(PG_FUNCTION_ARGS)
Datum pg_logdir_ls_v1_1(PG_FUNCTION_ARGS)
#define PG_RETURN_INT64(x)
bool path_is_prefix_of_path(const char *path1, const char *path2)
char * psprintf(const char *fmt,...)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void canonicalize_path(char *path)
int errcode(int sqlerrcode)
#define PG_GETARG_BOOL(n)
static Datum pg_logdir_ls_internal(FunctionCallInfo fcinfo)
bool path_contains_parent_reference(const char *path)
Datum pg_file_unlink_v1_1(PG_FUNCTION_ARGS)
static void requireSuperuser(void)
HeapTuple BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
#define PG_GETARG_TEXT_PP(n)
int DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp)
Datum pg_file_unlink(PG_FUNCTION_ARGS)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
Datum pg_logdir_ls(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pg_file_write)
int errcode_for_file_access(void)
#define is_absolute_path(filename)
bool path_is_relative_and_below_cwd(const char *path)
FILE * AllocateFile(const char *name, const char *mode)
DIR * AllocateDir(const char *dirname)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Datum pg_file_rename(PG_FUNCTION_ARGS)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
#define PG_RETURN_BOOL(x)
AttInMetadata * TupleDescGetAttInMetadata(TupleDesc tupdesc)
#define ereport(elevel,...)
Datum pg_file_sync(PG_FUNCTION_ARGS)
bool is_member_of_role(Oid member, Oid role)
SetFunctionReturnMode returnMode
Datum pg_file_rename_v1_1(PG_FUNCTION_ARGS)
struct dirent * ReadDir(DIR *dir, const char *dirname)
MemoryContext ecxt_per_query_memory
static int64 pg_file_write_internal(text *file, text *data, bool replace)
Tuplestorestate * setResult
static Datum values[MAXATTR]
char * text_to_cstring(const text *t)
#define VARSIZE_ANY_EXHDR(PTR)
int errmsg(const char *fmt,...)
int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, char **field, int *ftype, int maxfields, int *numfields)
int fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)