63#define K_STD_BUF_SIZE 1024
135 AH->ReopenPtr =
NULL;
146 AH->DeClonePtr =
NULL;
148 AH->WorkerJobDumpPtr =
NULL;
149 AH->WorkerJobRestorePtr =
NULL;
155 AH->formatData = ctx;
164 if (AH->fSpec &&
strcmp(AH->fSpec,
"") != 0)
168 pg_fatal(
"could not open TOC file \"%s\" for output: %m",
175 pg_fatal(
"could not open TOC file for output: %m");
194 pg_fatal(
"compression is not supported by tar archive format");
198 if (AH->fSpec &&
strcmp(AH->fSpec,
"") != 0)
202 pg_fatal(
"could not open TOC file \"%s\" for input: %m",
209 pg_fatal(
"could not open TOC file for input: %m");
330 pg_fatal(
"compression is not supported by tar archive format");
378 pg_fatal(
"could not generate temporary file name: %m");
385 pg_fatal(
"compression is not supported by tar archive format");
401 pg_fatal(
"compression is not supported by tar archive format");
426 if (
len > (
th->fileLen -
th->pos))
429 while (cnt <
len &&
c !=
'\n')
515 if (
th->pos +
len >
th->fileLen)
619 pg_fatal(
"unexpected COPY statement syntax: \"%s\"",
625 ahprintf(AH,
" FROM '$$PATH$$/%s';\n\n",
tctx->filename);
678 if (
strncmp(
th->targetFile,
"blob_", 5) == 0)
683 pg_log_info(
"restoring large object with OID %u", oid);
740 pg_fatal(
"could not read from input file: end of file");
763 pg_fatal(
"could not read from input file: end of file");
804 "-- File paths need to be edited. Search for $$PATH$$ and\n"
805 "-- replace it with the path to the directory containing\n"
806 "-- the extracted data files.\n"
849 if (AH->dosync && AH->fSpec)
903 pg_fatal(
"invalid OID for large object (%u)", oid);
906 pg_fatal(
"compression is not supported by tar archive format");
908 sprintf(fname,
"blob_%u.dat", oid);
1029 pg_fatal(
"error during file seek: %m");
1031 if (
th->fileLen < 0)
1032 pg_fatal(
"could not determine seek position in archive file: %m");
1034 pg_fatal(
"error during file seek: %m");
1038 while ((cnt =
fread(
buf, 1,
sizeof(
buf), tmp)) > 0)
1040 if ((res =
fwrite(
buf, 1, cnt,
th->tarFH)) != cnt)
1048 pg_fatal(
"could not close temporary file: %m");
1050 if (
len !=
th->fileLen)
1051 pg_fatal(
"actual file length (%lld) does not match expected (%lld)",
1052 (
long long)
len, (
long long)
th->fileLen);
1055 for (
i = 0;
i < pad;
i++)
1082 pg_log_debug(
"moving from position %lld to next member at file position %lld",
1097 pg_fatal(
"could not find header for file \"%s\" in tar archive",
filename);
1113 id =
atoi(
th->targetFile);
1115 pg_fatal(
"restoring data out of order is not supported in this archive format: "
1116 "\"%s\" is required, but comes before \"%s\" in the archive file.",
1128 pg_fatal(
"could not find header for file \"%s\" in tar archive",
filename);
1163 "incomplete tar header found (%lu bytes)",
1165 (
unsigned long)
len);
1197 pg_log_debug(
"TOC Entry %s at %llu (length %llu, checksum %d)",
1198 tag, (
unsigned long long)
hPos, (
unsigned long long)
len, sum);
1201 pg_fatal(
"corrupt tar header found in %s (expected %d, computed %d) file position %llu",
1217 0600, 04000, 02000, time(
NULL));
#define ngettext(s, p, n)
#define Assert(condition)
#define pg_attribute_printf(f, a)
void fsync_fname(const char *fname, bool isdir)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
#define pg_malloc0_object(type)
#define pg_log_debug(...)
RestoreOptions * NewRestoreOptions(void)
void SetArchiveOptions(Archive *AH, DumpOptions *dopt, RestoreOptions *ropt)
void RestoreArchive(Archive *AHX)
int TocIDRequired(ArchiveHandle *AH, DumpId id)
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
void WriteHead(ArchiveHandle *AH)
char * ReadStr(ArchiveHandle *AH)
void StartRestoreLOs(ArchiveHandle *AH)
void WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
int ahprintf(ArchiveHandle *AH, const char *fmt,...)
void ReadHead(ArchiveHandle *AH)
void ReadToc(ArchiveHandle *AH)
void EndRestoreLO(ArchiveHandle *AH, Oid oid)
void WriteToc(ArchiveHandle *AH)
void EndRestoreLOs(ArchiveHandle *AH)
void StartRestoreLO(ArchiveHandle *AH, Oid oid, bool drop)
size_t WriteStr(ArchiveHandle *AH, const char *c)
#define READ_ERROR_EXIT(fd)
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static size_t tarRead(void *buf, size_t len, TAR_MEMBER *th)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static int tarPrintf(TAR_MEMBER *th, const char *fmt,...) pg_attribute_printf(2
static void _tarWriteHeader(TAR_MEMBER *th)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
void InitArchiveFmt_Tar(ArchiveHandle *AH)
static size_t _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
bool isValidTarHeader(char *header)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static TAR_MEMBER * tarOpen(ArchiveHandle *AH, const char *filename, char mode)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static size_t tarWrite(const void *buf, size_t len, TAR_MEMBER *th)
static int _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
static size_t _scriptOut(ArchiveHandle *AH, const void *buf, size_t len)
static TAR_MEMBER * _tarPositionTo(ArchiveHandle *AH, const char *filename)
static void _PrintFileData(ArchiveHandle *AH, char *filename)
static int static void _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
static void _LoadLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
static void tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
static PgChecksumMode mode
static char buf[DEFAULT_XLOG_SEG_SIZE]
uint64 read_tar_number(const char *s, int len)
static size_t tarPaddingBytesRequired(size_t len)
int tarChecksum(char *header)
enum tarError tarCreateHeader(char *h, const char *filename, const char *linktarget, pgoff_t size, mode_t mode, uid_t uid, gid_t gid, time_t mtime)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int fd(const char *x, int i)
size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
CustomOutPtrType CustomOutPtr
pg_compress_specification compression_spec
struct _tocEntry * currToc
pg_compress_algorithm algorithm
static void * fn(void *arg)
#define fseeko(stream, offset, origin)