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

Function sendFileWithContent

src/backend/replication/basebackup.c:1256–1313  ·  view source on GitHub ↗

* Inject a file with given name and content in the output tar stream. */

Source from the content-addressed store, hash-verified

1254 * Inject a file with given name and content in the output tar stream.
1255 */
1256static void
1257sendFileWithContent(const char *filename, const char *content,
1258 backup_manifest_info *manifest)
1259{
1260 struct stat statbuf;
1261 int pad,
1262 len;
1263 pg_checksum_context checksum_ctx;
1264
1265 if (pg_checksum_init(&checksum_ctx, manifest->checksum_type) < 0)
1266 elog(ERROR, "could not initialize checksum of file \"%s\"",
1267 filename);
1268
1269 len = strlen(content);
1270
1271 /*
1272 * Construct a stat struct for the backup_label file we're injecting in
1273 * the tar.
1274 */
1275 /* Windows doesn't have the concept of uid and gid */
1276#ifdef WIN32
1277 statbuf.st_uid = 0;
1278 statbuf.st_gid = 0;
1279#else
1280 statbuf.st_uid = geteuid();
1281 statbuf.st_gid = getegid();
1282#endif
1283 statbuf.st_mtime = time(NULL);
1284 statbuf.st_mode = pg_file_create_mode;
1285 statbuf.st_size = len;
1286
1287 _tarWriteHeader(filename, NULL, &statbuf, false);
1288 /* Send the contents as a CopyData message */
1289 pq_putmessage('d', content, len);
1290 update_basebackup_progress(len);
1291
1292 /* Pad to a multiple of the tar block size. */
1293 pad = tarPaddingBytesRequired(len);
1294 if (pad > 0)
1295 {
1296 char buf[TAR_BLOCK_SIZE];
1297
1298 MemSet(buf, 0, pad);
1299 pq_putmessage('d', buf, pad);
1300 update_basebackup_progress(pad);
1301 }
1302
1303 elogif(debug_basebackup, LOG,
1304 "basebackup send file -- Sent file '%s' with content \n%s.",
1305 filename, content);
1306
1307 if (pg_checksum_update(&checksum_ctx, (uint8 *) content, len) < 0)
1308 elog(ERROR, "could not update checksum of file \"%s\"",
1309 filename);
1310
1311 AddFileToBackupManifest(manifest, NULL, filename, len,
1312 (pg_time_t) statbuf.st_mtime, &checksum_ctx);
1313}

Callers 1

perform_base_backupFunction · 0.85

Calls 6

pg_checksum_initFunction · 0.85
tarPaddingBytesRequiredFunction · 0.85
pg_checksum_updateFunction · 0.85
AddFileToBackupManifestFunction · 0.85
_tarWriteHeaderFunction · 0.70

Tested by

no test coverage detected