Skip to content

Commit 967a17f

Browse files
committed
Refactor basebackup.c's _tarWriteDir() function.
Sometimes, we replace a symbolic link that we find in the data directory with an actual directory within the tarfile that we create. _tarWriteDir was responsible both for making this substitution and also for writing the tar header for the resulting directory into the tar file. Make it do only the first of those things, and rename to convert_link_to_directory. Substantially larger refactoring of this source file is planned, but this little bit seemed to make sense to commit independently. Discussion: http://postgr.es/m/CA+Tgmobz6tuv5tr-WxURe5JA1vVcGz85k4kkvoWxcyHvDpEqFA@mail.gmail.com
1 parent d9ddc50 commit 967a17f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/backend/replication/basebackup.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ static void sendFileWithContent(const char *filename, const char *content,
7171
backup_manifest_info *manifest);
7272
static int64 _tarWriteHeader(const char *filename, const char *linktarget,
7373
struct stat *statbuf, bool sizeonly);
74-
static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
75-
bool sizeonly);
74+
static void convert_link_to_directory(const char *pathbuf, struct stat *statbuf);
7675
static void send_int8_string(StringInfoData *buf, int64 intval);
7776
static void SendBackupHeader(List *tablespaces);
7877
static void perform_base_backup(basebackup_options *opt);
@@ -1381,7 +1380,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
13811380
if (strcmp(de->d_name, excludeDirContents[excludeIdx]) == 0)
13821381
{
13831382
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", de->d_name);
1384-
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
1383+
convert_link_to_directory(pathbuf, &statbuf);
1384+
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
1385+
sizeonly);
13851386
excludeFound = true;
13861387
break;
13871388
}
@@ -1397,7 +1398,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
13971398
if (statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0)
13981399
{
13991400
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", statrelpath);
1400-
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
1401+
convert_link_to_directory(pathbuf, &statbuf);
1402+
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
1403+
sizeonly);
14011404
continue;
14021405
}
14031406

@@ -1409,7 +1412,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
14091412
if (strcmp(pathbuf, "./pg_wal") == 0)
14101413
{
14111414
/* If pg_wal is a symlink, write it as a directory anyway */
1412-
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
1415+
convert_link_to_directory(pathbuf, &statbuf);
1416+
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
1417+
sizeonly);
14131418

14141419
/*
14151420
* Also send archive_status directory (by hackishly reusing
@@ -1883,12 +1888,11 @@ _tarWriteHeader(const char *filename, const char *linktarget,
18831888
}
18841889

18851890
/*
1886-
* Write tar header for a directory. If the entry in statbuf is a link then
1887-
* write it as a directory anyway.
1891+
* If the entry in statbuf is a link, then adjust statbuf to make it look like a
1892+
* directory, so that it will be written that way.
18881893
*/
1889-
static int64
1890-
_tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
1891-
bool sizeonly)
1894+
static void
1895+
convert_link_to_directory(const char *pathbuf, struct stat *statbuf)
18921896
{
18931897
/* If symlink, write it as a directory anyway */
18941898
#ifndef WIN32
@@ -1897,8 +1901,6 @@ _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
18971901
if (pgwin32_is_junction(pathbuf))
18981902
#endif
18991903
statbuf->st_mode = S_IFDIR | pg_dir_create_mode;
1900-
1901-
return _tarWriteHeader(pathbuf + basepathlen + 1, NULL, statbuf, sizeonly);
19021904
}
19031905

19041906
/*

0 commit comments

Comments
 (0)