PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
fetch.c
Go to the documentation of this file.
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-2017, PostgreSQL Global Development Group
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include "postgres_fe.h"
18 
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 
23 #include "pg_rewind.h"
24 #include "fetch.h"
25 #include "file_ops.h"
26 #include "filemap.h"
27 
28 void
30 {
31  if (datadir_source)
33  else
35 }
36 
37 /*
38  * Fetch all relation data files that are marked in the given data page map.
39  */
40 void
42 {
43  if (datadir_source)
45  else
47 }
48 
49 /*
50  * Fetch a single file into a malloc'd buffer. The file size is returned
51  * in *filesize. The returned buffer is always zero-terminated, which is
52  * handy for text files.
53  */
54 char *
55 fetchFile(char *filename, size_t *filesize)
56 {
57  if (datadir_source)
58  return slurpFile(datadir_source, filename, filesize);
59  else
60  return libpqGetFile(filename, filesize);
61 }
void fetchSourceFileList(void)
Definition: fetch.c:29
void executeFileMap(void)
Definition: fetch.c:41
char * fetchFile(char *filename, size_t *filesize)
Definition: fetch.c:55
filemap_t * filemap
Definition: filemap.c:26
void copy_executeFileMap(filemap_t *map)
Definition: copy_fetch.c:210
void traverse_datadir(const char *datadir, process_file_callback_t callback)
Definition: copy_fetch.c:38
char * datadir_source
Definition: pg_rewind.c:50
void libpqProcessFileList(void)
Definition: libpq_fetch.c:150
void libpq_executeFileMap(filemap_t *map)
Definition: libpq_fetch.c:412
char * libpqGetFile(const char *filename, size_t *filesize)
Definition: libpq_fetch.c:341
void process_source_file(const char *path, file_type_t type, size_t newsize, const char *link_target)
Definition: filemap.c:61
static char * filename
Definition: pg_dumpall.c:84
char * slurpFile(const char *datadir, const char *path, size_t *filesize)
Definition: file_ops.c:277