36static void clone_file(
const char *fromfile,
const char *tofile);
48copydir(
const char *fromdir,
const char *todir,
bool recurse)
58 errmsg(
"could not create directory \"%s\": %m", todir)));
62 while ((xlde =
ReadDir(xldir, fromdir)) != NULL)
69 if (strcmp(xlde->
d_name,
".") == 0 ||
70 strcmp(xlde->
d_name,
"..") == 0)
73 snprintf(fromfile,
sizeof(fromfile),
"%s/%s", fromdir, xlde->
d_name);
82 copydir(fromfile, tofile,
true);
103 while ((xlde =
ReadDir(xldir, todir)) != NULL)
105 if (strcmp(xlde->
d_name,
".") == 0 ||
106 strcmp(xlde->
d_name,
"..") == 0)
143#define COPY_BUF_SIZE (8 * BLCKSZ)
151#if defined(__darwin__)
152#define FLUSH_DISTANCE (32 * 1024 * 1024)
154#define FLUSH_DISTANCE (1024 * 1024)
167 errmsg(
"could not open file \"%s\": %m", fromfile)));
173 errmsg(
"could not create file \"%s\": %m", tofile)));
179 for (offset = 0;; offset += nbytes)
192 flush_offset = offset;
201 errmsg(
"could not read file \"%s\": %m", fromfile)));
206 if ((
int)
write(
dstfd, buffer, nbytes) != nbytes)
213 errmsg(
"could not write to file \"%s\": %m", tofile)));
218 if (offset > flush_offset)
224 errmsg(
"could not close file \"%s\": %m", tofile)));
229 errmsg(
"could not close file \"%s\": %m", fromfile)));
240#if defined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE)
241 if (copyfile(fromfile, tofile, NULL, COPYFILE_CLONE_FORCE) < 0)
244 errmsg(
"could not clone file \"%s\" to \"%s\": %m",
246#elif defined(HAVE_COPY_FILE_RANGE)
255 errmsg(
"could not open file \"%s\": %m", fromfile)));
261 errmsg(
"could not create file \"%s\": %m", tofile)));
271 nbytes = copy_file_range(srcfd, NULL,
dstfd, NULL, 1024 * 1024, 0);
272 if (nbytes < 0 && errno !=
EINTR)
275 errmsg(
"could not clone file \"%s\" to \"%s\": %m",
284 errmsg(
"could not close file \"%s\": %m", tofile)));
289 errmsg(
"could not close file \"%s\": %m", fromfile)));
static void clone_file(const char *fromfile, const char *tofile)
void copy_file(const char *fromfile, const char *tofile)
void copydir(const char *fromdir, const char *todir, bool recurse)
int errcode_for_file_access(void)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void pg_flush_data(int fd, off_t offset, off_t nbytes)
int MakePGDirectory(const char *directoryName)
int CloseTransientFile(int fd)
void fsync_fname(const char *fname, bool isdir)
DIR * AllocateDir(const char *dirname)
struct dirent * ReadDir(DIR *dir, const char *dirname)
int OpenTransientFile(const char *fileName, int fileFlags)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
void pfree(void *pointer)
#define CHECK_FOR_INTERRUPTS()
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)