Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7606175

Browse files
committed
Extend sendFileWithContent() to handle custom content length in basebackup.c
sendFileWithContent() previously got the content length by usingstrlen(), assuming that the content given is always a string. Somepatches are under discussion to pass binary contents to a base backupstream, where an arbitrary length needs to be given by the callerinstead.The patch extends sendFileWithContent() to be able to handle this case,where len < 0 can be used to indicate an arbitrary length rather thanrely on strlen() for the content length.A comment in sendFileWithContent() mentioned the backup_label file.However, this routine is used by more file types, like the tablespacemap, so adjust it in passing.Author: David SteeleDiscussion:https://postgr.es/m/2daf8adc-8db7-4204-a7f2-a7e94e2bfa4b@pgmasters.net
1 parent23c8c0c commit7606175

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

‎src/backend/backup/basebackup.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static bool verify_page_checksum(Page page, XLogRecPtr start_lsn,
9494
BlockNumberblkno,
9595
uint16*expected_checksum);
9696
staticvoidsendFileWithContent(bbsink*sink,constchar*filename,
97-
constchar*content,
97+
constchar*content,intlen,
9898
backup_manifest_info*manifest);
9999
staticint64_tarWriteHeader(bbsink*sink,constchar*filename,
100100
constchar*linktarget,structstat*statbuf,
@@ -334,14 +334,14 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
334334
/* In the main tar, include the backup_label first... */
335335
backup_label=build_backup_content(backup_state, false);
336336
sendFileWithContent(sink,BACKUP_LABEL_FILE,
337-
backup_label,&manifest);
337+
backup_label,-1,&manifest);
338338
pfree(backup_label);
339339

340340
/* Then the tablespace_map file, if required... */
341341
if (opt->sendtblspcmapfile)
342342
{
343343
sendFileWithContent(sink,TABLESPACE_MAP,
344-
tablespace_map->data,&manifest);
344+
tablespace_map->data,-1,&manifest);
345345
sendtblspclinks= false;
346346
}
347347

@@ -601,7 +601,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
601601
* complete segment.
602602
*/
603603
StatusFilePath(pathbuf,walFileName,".done");
604-
sendFileWithContent(sink,pathbuf,"",&manifest);
604+
sendFileWithContent(sink,pathbuf,"",-1,&manifest);
605605
}
606606

607607
/*
@@ -629,7 +629,7 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
629629

630630
/* unconditionally mark file as archived */
631631
StatusFilePath(pathbuf,fname,".done");
632-
sendFileWithContent(sink,pathbuf,"",&manifest);
632+
sendFileWithContent(sink,pathbuf,"",-1,&manifest);
633633
}
634634

635635
/* Properly terminate the tar file. */
@@ -1037,26 +1037,29 @@ SendBaseBackup(BaseBackupCmd *cmd)
10371037

10381038
/*
10391039
* Inject a file with given name and content in the output tar stream.
1040+
*
1041+
* "len" can optionally be set to an arbitrary length of data sent. If set
1042+
* to -1, the content sent is treated as a string with strlen() as length.
10401043
*/
10411044
staticvoid
10421045
sendFileWithContent(bbsink*sink,constchar*filename,constchar*content,
1043-
backup_manifest_info*manifest)
1046+
intlen,backup_manifest_info*manifest)
10441047
{
10451048
structstatstatbuf;
1046-
intbytes_done=0,
1047-
len;
1049+
intbytes_done=0;
10481050
pg_checksum_contextchecksum_ctx;
10491051

10501052
if (pg_checksum_init(&checksum_ctx,manifest->checksum_type)<0)
10511053
elog(ERROR,"could not initialize checksum of file \"%s\"",
10521054
filename);
10531055

1054-
len=strlen(content);
1056+
if (len<0)
1057+
len=strlen(content);
10551058

10561059
/*
1057-
* Construct a stat struct for the backup_label file we're injecting in
1058-
* the tar.
1060+
* Construct a stat struct for the file we're injecting in the tar.
10591061
*/
1062+
10601063
/* Windows doesn't have the concept of uid and gid */
10611064
#ifdefWIN32
10621065
statbuf.st_uid=0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp