#include "postgres_fe.h"
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include "common/file_perm.h"
#include "common/logging.h"
#include "copy_file.h"
Go to the source code of this file.
|
| static void | copy_file_blocks (const char *src, const char *dst, pg_checksum_context *checksum_ctx) |
| |
| static void | copy_file_clone (const char *src, const char *dest, pg_checksum_context *checksum_ctx) |
| |
| static void | copy_file_by_range (const char *src, const char *dest, pg_checksum_context *checksum_ctx) |
| |
| static void | copy_file_link (const char *src, const char *dest, pg_checksum_context *checksum_ctx) |
| |
| void | copy_file (const char *src, const char *dst, pg_checksum_context *checksum_ctx, CopyMethod copy_method, bool dry_run) |
| |
| static void | checksum_file (const char *src, pg_checksum_context *checksum_ctx) |
| |
◆ checksum_file()
Definition at line 141 of file copy_file.c.
142{
145 const int buffer_size = 50 *
BLCKSZ;
147
148
150 return;
151
153 pg_fatal(
"could not open file \"%s\": %m", src);
154
156
158 {
160 pg_fatal(
"could not update checksum of file \"%s\"", src);
161 }
162
164 pg_fatal(
"could not read file \"%s\": %m", src);
165
168}
int pg_checksum_update(pg_checksum_context *context, const uint8 *input, size_t len)
void * pg_malloc(size_t size)
References CHECKSUM_TYPE_NONE, close, fb(), PG_BINARY, pg_checksum_update(), pg_fatal, pg_free(), pg_malloc(), read, and pg_checksum_context::type.
Referenced by copy_file_by_range(), copy_file_clone(), and copy_file_link().
◆ copy_file()
Definition at line 52 of file copy_file.c.
55{
59
60
61
62
63
65 {
67
69 pg_fatal(
"could not open file \"%s\": %m", src);
71 pg_fatal(
"could not close file \"%s\": %m", src);
72 }
73
74#ifdef WIN32
75
76
77
78
79
80
83#endif
84
85
86 switch (copy_method)
87 {
91 break;
93
95 break;
99 break;
100#ifdef WIN32
104 break;
105#endif
109 break;
110 }
111
113 {
115 pg_log_debug(
"would copy \"%s\" to \"%s\" using strategy %s",
117 else
120 }
121 else
122 {
124 pg_log_debug(
"copying \"%s\" to \"%s\" using strategy %s",
129 else
130 pg_log_debug(
"copying \"%s\" to \"%s\" and checksumming with %s",
132
134 }
135}
char * pg_checksum_type_name(pg_checksum_type type)
static void copy_file_blocks(const char *src, const char *dst, pg_checksum_context *checksum_ctx)
static void copy_file_clone(const char *src, const char *dest, pg_checksum_context *checksum_ctx)
static void copy_file_link(const char *src, const char *dest, pg_checksum_context *checksum_ctx)
static void copy_file_by_range(const char *src, const char *dest, pg_checksum_context *checksum_ctx)
@ COPY_METHOD_COPY_FILE_RANGE
#define pg_log_debug(...)
static int fd(const char *x, int i)
References CHECKSUM_TYPE_NONE, close, copy_file_blocks(), copy_file_by_range(), copy_file_clone(), copy_file_link(), COPY_METHOD_CLONE, COPY_METHOD_COPY, COPY_METHOD_COPY_FILE_RANGE, COPY_METHOD_LINK, dry_run, fb(), fd(), PG_BINARY, pg_checksum_type_name(), pg_fatal, pg_log_debug, and pg_checksum_context::type.
◆ copy_file_blocks()
Definition at line 174 of file copy_file.c.
176{
180 const int buffer_size = 50 *
BLCKSZ;
182 unsigned offset = 0;
183
185 pg_fatal(
"could not open file \"%s\": %m", src);
186
190
192
194 {
196
198 {
200 pg_fatal(
"could not write to file \"%s\": %m",
dst);
201 else
202 pg_fatal(
"could not write to file \"%s\", offset %u: wrote %d of %d",
203 dst, offset, (
int)
wb, (
int)
rb);
204 }
205
207 pg_fatal(
"could not update checksum of file \"%s\"",
dst);
208
210 }
211
213 pg_fatal(
"could not read from file \"%s\": %m",
dst);
214
218}
References close, fb(), PG_BINARY, pg_checksum_update(), pg_fatal, pg_file_create_mode, pg_free(), pg_malloc(), read, and write.
Referenced by copy_file().
◆ copy_file_by_range()
Definition at line 273 of file copy_file.c.
275{
276#if defined(HAVE_COPY_FILE_RANGE)
280
282 pg_fatal(
"could not open file \"%s\": %m", src);
283
286 pg_fatal(
"could not create file \"%s\": %m", dest);
287
288 do
289 {
291 if (nbytes < 0)
292 pg_fatal(
"error while copying file range from \"%s\" to \"%s\": %m",
293 src, dest);
294 } while (nbytes > 0);
295
298#else
299 pg_fatal(
"copy_file_range not supported on this platform");
300#endif
301
302
304}
static void checksum_file(const char *src, pg_checksum_context *checksum_ctx)
References checksum_file(), close, fb(), PG_BINARY, pg_fatal, and pg_file_create_mode.
Referenced by copy_file().
◆ copy_file_clone()
Definition at line 227 of file copy_file.c.
229{
230#if defined(HAVE_COPYFILE) && defined(COPYFILE_CLONE_FORCE)
232 pg_fatal(
"error while cloning file \"%s\" to \"%s\": %m", src, dest);
233#elif defined(__linux__) && defined(FICLONE)
234 {
237
239 pg_fatal(
"could not open file \"%s\": %m", src);
240
243 pg_fatal(
"could not create file \"%s\": %m", dest);
244
246 {
248
250
251 pg_fatal(
"error while cloning file \"%s\" to \"%s\": %s",
253 }
254
257 }
258#else
259 pg_fatal(
"file cloning not supported on this platform");
260#endif
261
262
264}
References checksum_file(), close, fb(), PG_BINARY, pg_fatal, pg_file_create_mode, and strerror.
Referenced by copy_file().
◆ copy_file_link()