PostgreSQL Source Code  git master
pg_backup_null.c File Reference
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "fe_utils/string_utils.h"
#include "libpq/libpq-fs.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 229 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

230 {
231  /* Nothing to do */
232 }

◆ _EndBlob()

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

Definition at line 172 of file pg_backup_null.c.

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

Referenced by InitArchiveFmt_Null().

173 {
174  AH->WriteDataPtr = _WriteData;
175 
176  ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
177 }
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 185 of file pg_backup_null.c.

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

186 {
187  ahprintf(AH, "COMMIT;\n\n");
188 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _EndData()

static void _EndData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 117 of file pg_backup_null.c.

References ahprintf().

Referenced by InitArchiveFmt_Null().

118 {
119  ahprintf(AH, "\n\n");
120 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _PrintTocData()

static void _PrintTocData ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 196 of file pg_backup_null.c.

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

Referenced by InitArchiveFmt_Null().

197 {
198  if (te->dataDumper)
199  {
200  AH->currToc = te;
201 
202  if (strcmp(te->desc, "BLOBS") == 0)
203  _StartBlobs(AH, te);
204 
205  te->dataDumper((Archive *) AH, te->dataDumperArg);
206 
207  if (strcmp(te->desc, "BLOBS") == 0)
208  _EndBlobs(AH, te);
209 
210  AH->currToc = NULL;
211  }
212 }
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 145 of file pg_backup_null.c.

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

Referenced by InitArchiveFmt_Null().

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

◆ _StartBlobs()

static void _StartBlobs ( ArchiveHandle AH,
TocEntry te 
)
static

Definition at line 132 of file pg_backup_null.c.

References ahprintf().

Referenced by _PrintTocData(), and InitArchiveFmt_Null().

133 {
134  ahprintf(AH, "BEGIN;\n\n");
135 }
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

◆ _WriteBlobData()

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

Definition at line 98 of file pg_backup_null.c.

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

Referenced by _StartBlob().

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

◆ _WriteBuf()

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

Definition at line 222 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

223 {
224  /* Don't do anything */
225  return;
226 }

◆ _WriteByte()

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

Definition at line 215 of file pg_backup_null.c.

Referenced by InitArchiveFmt_Null().

216 {
217  /* Don't do anything */
218  return 0;
219 }

◆ _WriteData()

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

Definition at line 86 of file pg_backup_null.c.

References ahwrite().

Referenced by _EndBlob(), and InitArchiveFmt_Null().

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

◆ InitArchiveFmt_Null()

void InitArchiveFmt_Null ( ArchiveHandle AH)

Definition at line 49 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, exit_horribly(), _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().

50 {
51  /* Assuming static functions, this can be copied for each format. */
53  AH->EndDataPtr = _EndData;
55  AH->WriteBufPtr = _WriteBuf;
56  AH->ClosePtr = _CloseArchive;
57  AH->ReopenPtr = NULL;
59 
62  AH->EndBlobPtr = _EndBlob;
63  AH->EndBlobsPtr = _EndBlobs;
64  AH->ClonePtr = NULL;
65  AH->DeClonePtr = NULL;
66 
67  /* Initialize LO buffering */
68  AH->lo_buf_size = LOBBUFSIZE;
69  AH->lo_buf = (void *) pg_malloc(LOBBUFSIZE);
70 
71  /*
72  * Now prevent reading...
73  */
74  if (AH->mode == archModeRead)
75  exit_horribly(NULL, "this format cannot be read\n");
76 }
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)
void exit_horribly(const char *modulename, const char *fmt,...)
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)