diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:19:15 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:19:15 +0000 |
commit | 6eb9c5a5657d1fe77b55cc261450f3538d35a94d (patch) | |
tree | 657d8194422a5daccecfd42d654b8a245ef7b4c8 /src/bin/pg_rewind/fetch.c | |
parent | Initial commit. (diff) | |
download | postgresql-13-6eb9c5a5657d1fe77b55cc261450f3538d35a94d.tar.xz postgresql-13-6eb9c5a5657d1fe77b55cc261450f3538d35a94d.zip |
Adding upstream version 13.4.upstream/13.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bin/pg_rewind/fetch.c')
-rw-r--r-- | src/bin/pg_rewind/fetch.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/bin/pg_rewind/fetch.c b/src/bin/pg_rewind/fetch.c new file mode 100644 index 0000000..f18fe53 --- /dev/null +++ b/src/bin/pg_rewind/fetch.c @@ -0,0 +1,60 @@ +/*------------------------------------------------------------------------- + * + * fetch.c + * Functions for fetching files from a local or remote data dir + * + * This file forms an abstraction of getting files from the "source". + * There are two implementations of this interface: one for copying files + * from a data directory via normal filesystem operations (copy_fetch.c), + * and another for fetching files from a remote server via a libpq + * connection (libpq_fetch.c) + * + * + * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ +#include "postgres_fe.h" + +#include <sys/stat.h> +#include <unistd.h> + +#include "fetch.h" +#include "file_ops.h" +#include "filemap.h" +#include "pg_rewind.h" + +void +fetchSourceFileList(void) +{ + if (datadir_source) + traverse_datadir(datadir_source, &process_source_file); + else + libpqProcessFileList(); +} + +/* + * Fetch all relation data files that are marked in the given data page map. + */ +void +executeFileMap(void) +{ + if (datadir_source) + copy_executeFileMap(filemap); + else + libpq_executeFileMap(filemap); +} + +/* + * Fetch a single file into a malloc'd buffer. The file size is returned + * in *filesize. The returned buffer is always zero-terminated, which is + * handy for text files. + */ +char * +fetchFile(const char *filename, size_t *filesize) +{ + if (datadir_source) + return slurpFile(datadir_source, filename, filesize); + else + return libpqGetFile(filename, filesize); +} |