| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * fetch.c |
| 4 | * Functions for fetching files from a local or remote data dir |
| 5 | * |
| 6 | * This file forms an abstraction of getting files from the "source". |
| 7 | * There are two implementations of this interface: one for copying files |
| 8 | * from a data directory via normal filesystem operations (copy_fetch.c), |
| 9 | * and another for fetching files from a remote server via a libpq |
| 10 | * connection (libpq_fetch.c) |
| 11 | * |
| 12 | * |
| 13 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 14 | * |
| 15 | *------------------------------------------------------------------------- |
| 16 | */ |
| 17 | #include "postgres_fe.h" |
| 18 | |
| 19 | #include <sys/stat.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | #include "pg_rewind.h" |
| 23 | #include "fetch.h" |
| 24 | #include "file_ops.h" |
| 25 | #include "filemap.h" |
| 26 | |
| 27 | void |
| 28 | fetchSourceFileList(void) |
| 29 | { |
| 30 | if (datadir_source) |
| 31 | traverse_datadir(datadir_source, &process_source_file); |
| 32 | else |
| 33 | libpqProcessFileList(); |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Fetch all relation data files that are marked in the given data page map. |
| 38 | */ |
| 39 | void |
| 40 | executeFileMap(void) |
| 41 | { |
| 42 | if (datadir_source) |
| 43 | copy_executeFileMap(filemap); |
| 44 | else |
| 45 | libpq_executeFileMap(filemap); |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Fetch a single file into a malloc'd buffer. The file size is returned |
| 50 | * in *filesize. The returned buffer is always zero-terminated, which is |
| 51 | * handy for text files. |
| 52 | */ |
| 53 | char * |
| 54 | fetchFile(const char *filename, size_t *filesize) |
| 55 | { |
| 56 | if (datadir_source) |
| 57 | return slurpFile(datadir_source, filename, filesize); |
| 58 | else |
| 59 | return libpqGetFile(filename, filesize); |
| 60 | } |
| 61 | |