PostgreSQL Source Code  git master
pg_backup_null.c File Reference
#include "postgres_fe.h"
#include "fe_utils/string_utils.h"
#include "libpq/libpq-fs.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
Include dependency graph for pg_backup_null.c:

Go to the source code of this file.

Functions

static void _WriteData (ArchiveHandle *AH, const void *data, size_t dLen)
 
static void _WriteBlobData (ArchiveHandle *AH, const void *data, size_t dLen)
 
static void _EndData (ArchiveHandle *AH, TocEntry *te)
 
static int _WriteByte (ArchiveHandle *AH, const int i)
 
static void _WriteBuf (ArchiveHandle *AH, const void *buf, size_t len)
 
static void _CloseArchive (ArchiveHandle *AH)
 
static void _PrintTocData (ArchiveHandle *AH, TocEntry *te)
 
static void _StartBlobs (ArchiveHandle *AH, TocEntry *te)
 
static void _StartBlob (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void _EndBlob (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
static void _EndBlobs (ArchiveHandle *AH, TocEntry *te)
 
void InitArchiveFmt_Null (ArchiveHandle *AH)
 

Function Documentation

◆ _CloseArchive()

static void _CloseArchive ( ArchiveHandle AH)
static

Definition at line 225 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

226 {
227  /* Nothing to do */
228 }

◆ _EndBlob()

static void _EndBlob ( ArchiveHandle AH,
TocEntry te,
Oid  oid 
)
static

Definition at line 169 of file pg_backup_null.c.

References _WriteData(), ahprintf(), and _archiveHandle::WriteDataPtr.

Referenced by InitArchiveFmt_Null().

170 {
171  AH->WriteDataPtr = _WriteData;
172 
173  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
174 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
WriteDataPtrType WriteDataPtr
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)

◆ _EndBlobs()

static void _EndBlobs ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 182 of file pg_backup_null.c.

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

183 {
184  ahprintf(AH, "COMMIT;\n\n");
185 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _EndData()

static void _EndData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 114 of file pg_backup_null.c.

References ahprintf().

Referenced by InitArchiveFmt_Null().

115 {
116  ahprintf(AH, "\n\n");
117 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _PrintTocData()

static void _PrintTocData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 193 of file pg_backup_null.c.

References _EndBlobs(), _StartBlobs(), _archiveHandle::currToc, _tocEntry::dataDumper, _tocEntry::dataDumperArg, and _tocEntry::desc.

Referenced by InitArchiveFmt_Null().

194 {
195  if (te->dataDumper)
196  {
197  AH->currToc = te;
198 
199  if (strcmp(te->desc, "BLOBS") == 0)
200  _StartBlobs(AH, te);
201 
202  te->dataDumper((Archive *) AH, te->dataDumperArg);
203 
204  if (strcmp(te->desc, "BLOBS") == 0)
205  _EndBlobs(AH, te);
206 
207  AH->currToc = NULL;
208  }
209 }
void * dataDumperArg
DataDumperPtr dataDumper
struct _tocEntry * currToc
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)

◆ _StartBlob()

static void _StartBlob ( ArchiveHandle AH,
TocEntry te,
Oid  oid 
)
static

Definition at line 142 of file pg_backup_null.c.

References _WriteBlobData(), ahprintf(), DropBlobIfExists(), _restoreOptions::dropSchema, fatal, INV_WRITE, K_VERS_1_12, _archiveHandle::public, Archive::ropt, _archiveHandle::version, and _archiveHandle::WriteDataPtr.

Referenced by InitArchiveFmt_Null().

143 {
144  bool old_blob_style = (AH->version < K_VERS_1_12);
145 
146  if (oid == 0)
147  fatal("invalid OID for large object");
148 
149  /* With an old archive we must do drop and create logic here */
150  if (old_blob_style && AH->public.ropt->dropSchema)
151  DropBlobIfExists(AH, oid);
152 
153  if (old_blob_style)
154  ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
155  oid, INV_WRITE);
156  else
157  ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
158  oid, INV_WRITE);
159 
161 }
static void _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen)
void DropBlobIfExists(ArchiveHandle *AH, Oid oid)
Definition: pg_backup_db.c:656
RestoreOptions * ropt
Definition: pg_backup.h:183
#define K_VERS_1_12
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
WriteDataPtrType WriteDataPtr
#define fatal(...)
#define INV_WRITE
Definition: libpq-fs.h:21

◆ _StartBlobs()

static void _StartBlobs ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 129 of file pg_backup_null.c.

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

130 {
131  ahprintf(AH, "BEGIN;\n\n");
132 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _WriteBlobData()

static void _WriteBlobData ( ArchiveHandle AH,
const void *  data,
size_t  dLen 
)
static

Definition at line 96 of file pg_backup_null.c.

References ahprintf(), appendByteaLiteralAHX, buf, createPQExpBuffer(), PQExpBufferData::data, and destroyPQExpBuffer().

Referenced by _StartBlob().

97 {
98  if (dLen > 0)
99  {
101 
103  (const unsigned char *) data,
104  dLen,
105  AH);
106 
107  ahprintf(AH, "SELECT pg_catalog.lowrite(0, %s);\n", buf->data);
108 
109  destroyPQExpBuffer(buf);
110  }
111 }
#define appendByteaLiteralAHX(buf, str, len, AH)
void destroyPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:116
static char * buf
Definition: pg_test_fsync.c:67
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
Definition: pqexpbuffer.c:74

◆ _WriteBuf()

static void _WriteBuf ( ArchiveHandle AH,
const void *  buf,
size_t  len 
)
static

Definition at line 219 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

220 {
221  /* Don't do anything */
222 }

◆ _WriteByte()

static int _WriteByte ( ArchiveHandle AH,
const int  i 
)
static

Definition at line 212 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

213 {
214  /* Don't do anything */
215  return 0;
216 }

◆ _WriteData()

static void _WriteData ( ArchiveHandle AH,
const void *  data,
size_t  dLen 
)
static

Definition at line 85 of file pg_backup_null.c.

References ahwrite().

Referenced by _EndBlob(), and InitArchiveFmt_Null().

86 {
87  /* Just send it to output, ahwrite() already errors on failure */
88  ahwrite(data, 1, dLen, AH);
89 }
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)

◆ InitArchiveFmt_Null()

void InitArchiveFmt_Null ( ArchiveHandle AH)

Definition at line 48 of file pg_backup_null.c.

References _CloseArchive(), _EndBlob(), _EndBlobs(), _EndData(), _PrintTocData(), _StartBlob(), _StartBlobs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndBlobPtr, _archiveHandle::EndBlobsPtr, _archiveHandle::EndDataPtr, fatal, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, LOBBUFSIZE, _archiveHandle::mode, pg_malloc(), _archiveHandle::PrintTocDataPtr, _archiveHandle::ReopenPtr, _archiveHandle::StartBlobPtr, _archiveHandle::StartBlobsPtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, and _archiveHandle::WriteDataPtr.

Referenced by _allocAH().

49 {
50  /* Assuming static functions, this can be copied for each format. */
52  AH->EndDataPtr = _EndData;
54  AH->WriteBufPtr = _WriteBuf;
55  AH->ClosePtr = _CloseArchive;
56  AH->ReopenPtr = NULL;
58 
61  AH->EndBlobPtr = _EndBlob;
62  AH->EndBlobsPtr = _EndBlobs;
63  AH->ClonePtr = NULL;
64  AH->DeClonePtr = NULL;
65 
66  /* Initialize LO buffering */
67  AH->lo_buf_size = LOBBUFSIZE;
68  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
69 
70  /*
71  * Now prevent reading...
72  */
73  if (AH->mode == archModeRead)
74  fatal("this format cannot be read");
75 }
ReopenPtrType ReopenPtr
DeClonePtrType DeClonePtr
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
WriteBufPtrType WriteBufPtr
StartBlobPtrType StartBlobPtr
EndDataPtrType EndDataPtr
StartBlobsPtrType StartBlobsPtr
EndBlobPtrType EndBlobPtr
static void _CloseArchive(ArchiveHandle *AH)
static void _EndBlobs(ArchiveHandle *AH, TocEntry *te)
WriteBytePtrType WriteBytePtr
static void _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te)
PrintTocDataPtrType PrintTocDataPtr
WriteDataPtrType WriteDataPtr
static void _EndData(ArchiveHandle *AH, TocEntry *te)
EndBlobsPtrType EndBlobsPtr
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
#define fatal(...)
ClonePtrType ClonePtr
ClosePtrType ClosePtr
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
#define LOBBUFSIZE
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)