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
This commit is contained in:
parent
d9ddc50baf
commit
967a17fe2f
|
@ -71,8 +71,7 @@ static void sendFileWithContent(const char *filename, const char *content,
|
||||||
backup_manifest_info *manifest);
|
backup_manifest_info *manifest);
|
||||||
static int64 _tarWriteHeader(const char *filename, const char *linktarget,
|
static int64 _tarWriteHeader(const char *filename, const char *linktarget,
|
||||||
struct stat *statbuf, bool sizeonly);
|
struct stat *statbuf, bool sizeonly);
|
||||||
static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
|
static void convert_link_to_directory(const char *pathbuf, struct stat *statbuf);
|
||||||
bool sizeonly);
|
|
||||||
static void send_int8_string(StringInfoData *buf, int64 intval);
|
static void send_int8_string(StringInfoData *buf, int64 intval);
|
||||||
static void SendBackupHeader(List *tablespaces);
|
static void SendBackupHeader(List *tablespaces);
|
||||||
static void perform_base_backup(basebackup_options *opt);
|
static void perform_base_backup(basebackup_options *opt);
|
||||||
|
@ -1381,7 +1380,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
||||||
if (strcmp(de->d_name, excludeDirContents[excludeIdx]) == 0)
|
if (strcmp(de->d_name, excludeDirContents[excludeIdx]) == 0)
|
||||||
{
|
{
|
||||||
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", de->d_name);
|
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", de->d_name);
|
||||||
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
convert_link_to_directory(pathbuf, &statbuf);
|
||||||
|
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
|
||||||
|
sizeonly);
|
||||||
excludeFound = true;
|
excludeFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1397,7 +1398,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
||||||
if (statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0)
|
if (statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0)
|
||||||
{
|
{
|
||||||
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", statrelpath);
|
elog(DEBUG1, "contents of directory \"%s\" excluded from backup", statrelpath);
|
||||||
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
convert_link_to_directory(pathbuf, &statbuf);
|
||||||
|
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
|
||||||
|
sizeonly);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1409,7 +1412,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
||||||
if (strcmp(pathbuf, "./pg_wal") == 0)
|
if (strcmp(pathbuf, "./pg_wal") == 0)
|
||||||
{
|
{
|
||||||
/* If pg_wal is a symlink, write it as a directory anyway */
|
/* If pg_wal is a symlink, write it as a directory anyway */
|
||||||
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
convert_link_to_directory(pathbuf, &statbuf);
|
||||||
|
size += _tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf,
|
||||||
|
sizeonly);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Also send archive_status directory (by hackishly reusing
|
* Also send archive_status directory (by hackishly reusing
|
||||||
|
@ -1883,12 +1888,11 @@ _tarWriteHeader(const char *filename, const char *linktarget,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write tar header for a directory. If the entry in statbuf is a link then
|
* If the entry in statbuf is a link, then adjust statbuf to make it look like a
|
||||||
* write it as a directory anyway.
|
* directory, so that it will be written that way.
|
||||||
*/
|
*/
|
||||||
static int64
|
static void
|
||||||
_tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
|
convert_link_to_directory(const char *pathbuf, struct stat *statbuf)
|
||||||
bool sizeonly)
|
|
||||||
{
|
{
|
||||||
/* If symlink, write it as a directory anyway */
|
/* If symlink, write it as a directory anyway */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
@ -1897,8 +1901,6 @@ _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
|
||||||
if (pgwin32_is_junction(pathbuf))
|
if (pgwin32_is_junction(pathbuf))
|
||||||
#endif
|
#endif
|
||||||
statbuf->st_mode = S_IFDIR | pg_dir_create_mode;
|
statbuf->st_mode = S_IFDIR | pg_dir_create_mode;
|
||||||
|
|
||||||
return _tarWriteHeader(pathbuf + basepathlen + 1, NULL, statbuf, sizeonly);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue