MCPcopy Create free account
hub / github.com/apache/cloudberry / ReceiveTarFile

Function ReceiveTarFile

src/bin/pg_basebackup/pg_basebackup.c:1066–1321  ·  view source on GitHub ↗

* Receive a tar format file from the connection to the server, and write * the data from this file directly into a tar file. If compression is * enabled, the data will be compressed while written to the file. * * The file will be named base.tar[.gz] if it's for the main data directory * or .tar[.gz] if it's for another tablespace. * * No attempt to inspect or validate the con

Source from the content-addressed store, hash-verified

1064 * No attempt to inspect or validate the contents of the file is done.
1065 */
1066static void
1067ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
1068{
1069 char zerobuf[TAR_BLOCK_SIZE * 2];
1070 WriteTarState state;
1071
1072 memset(&state, 0, sizeof(state));
1073 state.tablespacenum = rownum;
1074 state.basetablespace = PQgetisnull(res, rownum, 0);
1075 state.in_tarhdr = true;
1076
1077 /* recovery.conf is integrated into postgresql.conf in 12 and newer */
1078 if (PQserverVersion(conn) >= MINIMUM_VERSION_FOR_RECOVERY_GUC)
1079 state.is_recovery_guc_supported = true;
1080
1081 if (state.basetablespace)
1082 {
1083 /*
1084 * Base tablespaces
1085 */
1086 if (strcmp(basedir, "-") == 0)
1087 {
1088#ifdef WIN32
1089 _setmode(fileno(stdout), _O_BINARY);
1090#endif
1091
1092#ifdef HAVE_LIBZ
1093 if (compresslevel != 0)
1094 {
1095 int fd = dup(fileno(stdout));
1096
1097 if (fd < 0)
1098 {
1099 pg_log_error("could not duplicate stdout: %m");
1100 exit(1);
1101 }
1102
1103 state.ztarfile = gzdopen(fd, "wb");
1104 if (state.ztarfile == NULL)
1105 {
1106 pg_log_error("could not open output file: %m");
1107 exit(1);
1108 }
1109
1110 if (gzsetparams(state.ztarfile, compresslevel,
1111 Z_DEFAULT_STRATEGY) != Z_OK)
1112 {
1113 pg_log_error("could not set compression level %d: %s",
1114 compresslevel, get_gz_error(state.ztarfile));
1115 exit(1);
1116 }
1117 }
1118 else
1119#endif
1120 state.tarfile = stdout;
1121 strcpy(state.filename, "-");
1122 }
1123 else

Callers 1

BaseBackupFunction · 0.85

Calls 12

PQgetisnullFunction · 0.85
PQserverVersionFunction · 0.85
get_gz_errorFunction · 0.85
PQgetvalueFunction · 0.85
ReceiveCopyDataFunction · 0.85
tarCreateHeaderFunction · 0.85
tarPaddingBytesRequiredFunction · 0.85
writeTarDataFunction · 0.85
initPQExpBufferFunction · 0.85
termPQExpBufferFunction · 0.85
progress_reportFunction · 0.70

Tested by

no test coverage detected