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/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
29 {
30  if (datadir_source)
32  else
34 }
35 
36 /*
37  * Fetch all relation data files that are marked in the given data page map.
38  */
39 void
41 {
42  if (datadir_source)
44  else
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(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 }
void fetchSourceFileList(void)
Definition: fetch.c:28
void executeFileMap(void)
Definition: fetch.c:40
char * fetchFile(char *filename, size_t *filesize)
Definition: fetch.c:54
filemap_t * filemap
Definition: filemap.c:25
void copy_executeFileMap(filemap_t *map)
Definition: copy_fetch.c:208
void traverse_datadir(const char *datadir, process_file_callback_t callback)
Definition: copy_fetch.c:36
char * datadir_source
Definition: pg_rewind.c:51
void libpqProcessFileList(void)
Definition: libpq_fetch.c:149
void libpq_executeFileMap(filemap_t *map)
Definition: libpq_fetch.c:440
char * libpqGetFile(const char *filename, size_t *filesize)
Definition: libpq_fetch.c:368
void process_source_file(const char *path, file_type_t type, size_t newsize, const char *link_target)
Definition: filemap.c:60
static char * filename
Definition: pg_dumpall.c:90
char * slurpFile(const char *datadir, const char *path, size_t *filesize)
Definition: file_ops.c:276