v2-0002-Recast-_tarWriteDirectory-as-convert_link_to_dire.patch

application/octet-stream

Filename: v2-0002-Recast-_tarWriteDirectory-as-convert_link_to_dire.patch
Type: application/octet-stream
Part: 2
Message: Re: refactoring basebackup.c

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v2-0002
Subject: Recast _tarWriteDirectory as convert_link_to_directory.
File+
src/backend/replication/basebackup.c 14 12
From c2c768d2733ba5c13f72e15fe7930bc52ff911d1 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 1 May 2020 14:36:57 -0400
Subject: [PATCH v2 02/11] Recast _tarWriteDirectory as
 convert_link_to_directory.

So that it doesn't get tangled up in tar-specific considerations.
---
 src/backend/replication/basebackup.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index d43c34e8e9..6916132400 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -71,8 +71,7 @@ static void sendFileWithContent(const char *filename, const char *content,
 								backup_manifest_info *manifest);
 static int64 _tarWriteHeader(const char *filename, const char *linktarget,
 							 struct stat *statbuf, bool sizeonly);
-static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
-						  bool sizeonly);
+static void convert_link_to_directory(const char *pathbuf, struct stat *statbuf);
 static void send_int8_string(StringInfoData *buf, int64 intval);
 static void SendBackupHeader(List *tablespaces);
 static void perform_base_backup(basebackup_options *opt);
@@ -1356,7 +1355,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
 			if (strcmp(de->d_name, excludeDirContents[excludeIdx]) == 0)
 			{
 				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;
 				break;
 			}
@@ -1372,7 +1373,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
 		if (statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0)
 		{
 			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;
 		}
 
@@ -1384,7 +1387,9 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
 		if (strcmp(pathbuf, "./pg_wal") == 0)
 		{
 			/* 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
@@ -1854,12 +1859,11 @@ _tarWriteHeader(const char *filename, const char *linktarget,
 }
 
 /*
- * Write tar header for a directory.  If the entry in statbuf is a link then
- * write it as a directory anyway.
+ * If the entry in statbuf is a link, then adjust statbuf to make it look like a
+ * directory, so that it will be written that way.
  */
-static int64
-_tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
-			 bool sizeonly)
+static void
+convert_link_to_directory(const char *pathbuf, struct stat *statbuf)
 {
 	/* If symlink, write it as a directory anyway */
 #ifndef WIN32
@@ -1868,8 +1872,6 @@ _tarWriteDir(const char *pathbuf, int basepathlen, struct stat *statbuf,
 	if (pgwin32_is_junction(pathbuf))
 #endif
 		statbuf->st_mode = S_IFDIR | pg_dir_create_mode;
-
-	return _tarWriteHeader(pathbuf + basepathlen + 1, NULL, statbuf, sizeonly);
 }
 
 /*
-- 
2.24.3 (Apple Git-128)