26 #include "catalog/pg_tablespace_d.h"
83 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
84 errmsg(
"absolute path not allowed")));
88 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
89 errmsg(
"path must be in or below the data directory")));
113 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
114 errmsg(
"requested length too large")));
118 if (missing_ok && errno == ENOENT)
123 errmsg(
"could not open file \"%s\" for reading: %m",
127 if (
fseeko(file, (off_t) seek_offset,
128 (seek_offset >= 0) ? SEEK_SET : SEEK_END) != 0)
133 if (bytes_to_read >= 0)
138 nbytes = fread(
VARDATA(
buf), 1, (
size_t) bytes_to_read, file);
150 while (!(feof(file) || ferror(file)))
155 #define MIN_READ_SIZE 4096
168 if (fread(rbuf, 1, 1, file) != 0 || !feof(file))
170 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
171 errmsg(
"file length too large")));
184 rbytes = fread(sbuf.
data + sbuf.
len, 1,
185 (
size_t) (sbuf.
maxlen - sbuf.
len - 1), file);
241 bool read_to_eof,
bool missing_ok)
244 Assert(bytes_to_read == -1);
245 else if (bytes_to_read < 0)
247 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
248 errmsg(
"requested length cannot be negative")));
251 seek_offset, bytes_to_read, missing_ok);
261 int64 seek_offset, int64 bytes_to_read,
262 bool read_to_eof,
bool missing_ok)
265 Assert(bytes_to_read == -1);
266 else if (bytes_to_read < 0)
268 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
269 errmsg(
"requested length cannot be negative")));
272 seek_offset, bytes_to_read, missing_ok);
422 bool missing_ok =
false;
432 if (missing_ok && errno == ENOENT)
446 "size", INT8OID, -1, 0);
448 "access", TIMESTAMPTZOID, -1, 0);
450 "modification", TIMESTAMPTZOID, -1, 0);
452 "change", TIMESTAMPTZOID, -1, 0);
454 "creation", TIMESTAMPTZOID, -1, 0);
456 "isdir", BOOLOID, -1, 0);
459 memset(isnull,
false,
sizeof(isnull));
465 #if !defined(WIN32) && !defined(__CYGWIN__)
502 bool missing_ok =
false;
503 bool include_dot_dirs =
false;
524 if (missing_ok && errno == ENOENT)
529 while ((de =
ReadDir(dirdesc, location)) != NULL)
534 if (!include_dot_dirs &&
535 (strcmp(de->d_name,
".") == 0 ||
536 strcmp(de->d_name,
"..") == 0))
587 if (missing_ok && errno == ENOENT)
592 while ((de =
ReadDir(dirdesc, dir)) != NULL)
600 if (de->d_name[0] ==
'.')
604 snprintf(path,
sizeof(path),
"%s/%s", dir, de->d_name);
605 if (
stat(path, &attrib) < 0)
612 errmsg(
"could not stat file \"%s\": %m", path)));
622 memset(nulls, 0,
sizeof(nulls));
655 (
errcode(ERRCODE_UNDEFINED_OBJECT),
656 errmsg(
"tablespace with OID %u does not exist",
738 (
errcode(ERRCODE_UNDEFINED_OBJECT),
739 errmsg(
"replication slot \"%s\" does not exist",
bool has_privs_of_role(Oid member, Oid role)
TimestampTz time_t_to_timestamptz(pg_time_t tm)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
struct dirent * ReadDir(DIR *dir, const char *dirname)
FILE * AllocateFile(const char *name, const char *mode)
DIR * AllocateDir(const char *dirname)
void TempTablespacePath(char *path, Oid tablespace)
Datum Int64GetDatum(int64 X)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_INT64(n)
#define PG_RETURN_TEXT_P(x)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
#define MAT_SRF_USE_EXPECTED_DESC
Datum pg_read_file_off_len_missing(PG_FUNCTION_ARGS)
Datum pg_ls_summariesdir(PG_FUNCTION_ARGS)
Datum pg_read_file_off_len(PG_FUNCTION_ARGS)
Datum pg_read_binary_file_all_missing(PG_FUNCTION_ARGS)
Datum pg_read_binary_file_all(PG_FUNCTION_ARGS)
Datum pg_ls_logicalsnapdir(PG_FUNCTION_ARGS)
Datum pg_ls_waldir(PG_FUNCTION_ARGS)
Datum pg_ls_replslotdir(PG_FUNCTION_ARGS)
static bytea * pg_read_binary_file_common(text *filename_t, int64 seek_offset, int64 bytes_to_read, bool read_to_eof, bool missing_ok)
Datum pg_ls_dir(PG_FUNCTION_ARGS)
Datum pg_ls_archive_statusdir(PG_FUNCTION_ARGS)
Datum pg_stat_file(PG_FUNCTION_ARGS)
static Datum pg_ls_tmpdir(FunctionCallInfo fcinfo, Oid tblspc)
static bytea * read_binary_file(const char *filename, int64 seek_offset, int64 bytes_to_read, bool missing_ok)
static char * convert_and_check_filename(text *arg)
Datum pg_read_binary_file_off_len(PG_FUNCTION_ARGS)
Datum pg_ls_dir_1arg(PG_FUNCTION_ARGS)
Datum pg_read_binary_file_off_len_missing(PG_FUNCTION_ARGS)
Datum pg_read_file_all(PG_FUNCTION_ARGS)
Datum pg_ls_tmpdir_noargs(PG_FUNCTION_ARGS)
Datum pg_ls_logdir(PG_FUNCTION_ARGS)
Datum pg_ls_logicalmapdir(PG_FUNCTION_ARGS)
Datum pg_stat_file_1arg(PG_FUNCTION_ARGS)
Datum pg_read_file_all_missing(PG_FUNCTION_ARGS)
Datum pg_ls_tmpdir_1arg(PG_FUNCTION_ARGS)
static Datum pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir, bool missing_ok)
static text * read_text_file(const char *filename, int64 seek_offset, int64 bytes_to_read, bool missing_ok)
static text * pg_read_file_common(text *filename_t, int64 seek_offset, int64 bytes_to_read, bool read_to_eof, bool missing_ok)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
void pfree(void *pointer)
#define is_absolute_path(filename)
bool path_is_prefix_of_path(const char *path1, const char *path2)
bool path_is_relative_and_below_cwd(const char *path)
void canonicalize_path(char *path)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
#define PG_LOGICAL_SNAPSHOTS_DIR
#define PG_LOGICAL_MAPPINGS_DIR
ReplicationSlot * SearchNamedReplicationSlot(const char *name, bool need_lock)
void enlargeStringInfo(StringInfo str, int needed)
void initStringInfo(StringInfo str)
Tuplestorestate * setResult
#define SearchSysCacheExists1(cacheId, key1)
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
static Datum TimestampTzGetDatum(TimestampTz X)
#define SET_VARSIZE(PTR, len)
char * text_to_cstring(const text *t)
#define fseeko(stream, offset, origin)