[PATCH 3/6] pg_basebackup: factor out code to add a recovery.conf file to the tar file. - Mailing list pgsql-hackers

From Joshua Elsasser
Subject [PATCH 3/6] pg_basebackup: factor out code to add a recovery.conf file to the tar file.
Date
Msg-id 1443564988-17928-4-git-send-email-josh@idealist.org
Whole thread Raw
In response to Re: Add pg_basebackup single tar output format  (Joshua Elsasser <josh@idealist.org>)
List pgsql-hackers
This is just a simple refactor for readability and reusability.
---src/bin/pg_basebackup/pg_basebackup.c | 46 ++++++++++++++++++++---------------1 file changed, 26 insertions(+), 20
deletions(-)

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index fa942ab..f73dd38 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -111,6 +111,7 @@ static void progress_report(int tablespacenum, const char *filename, bool force)static void
OpenTarFile(TarStream*tarfile, const char *path);static void CloseTarFile(TarStream *tarfile);
 
+static void TarInsertRecoveryConf(TarStream *stream);static void ReceiveTarFile(PGconn *conn, PGresult *res, int
rownum);staticvoid ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum);static void
GenerateRecoveryConf(PGconn*conn);
 
@@ -874,6 +875,30 @@ CloseTarFile(TarStream *tarfile)/*
+ * Write a recovery.conf file into the tar stream.
+ */
+static void
+TarInsertRecoveryConf(TarStream *stream)
+{
+    static char    zerobuf[512];
+    char        header[512];
+    int            padding;
+
+    tarCreateHeader(header, "recovery.conf", NULL,
+                    recoveryconfcontents->len,
+                    0600, 04000, 02000,
+                    time(NULL));
+
+    padding = ((recoveryconfcontents->len + 511) & ~511) - recoveryconfcontents->len;
+
+    writeTarData(stream, header, sizeof(header));
+    writeTarData(stream, recoveryconfcontents->data, recoveryconfcontents->len);
+    if (padding)
+        writeTarData(stream, zerobuf, padding);
+}
+
+
+/* * Open a (possibly zlib-compressed) tar file for writing. The filebase * argument should be the desired filename
relativeto basedir, without a .tar * or .tar.gz file extension. If the user specified a basedir of - then stdout
 
@@ -957,27 +982,8 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)             * Also, write two completely
emptyblocks at the end of the tar             * file, as required by some tar programs.             */
 
-            char        zerobuf[1024];
-
-            MemSet(zerobuf, 0, sizeof(zerobuf));
-            if (basetablespace && writerecoveryconf)
-            {
-                char        header[512];
-                int            padding;
-
-                tarCreateHeader(header, "recovery.conf", NULL,
-                                recoveryconfcontents->len,
-                                0600, 04000, 02000,
-                                time(NULL));
-
-                padding = ((recoveryconfcontents->len + 511) & ~511) - recoveryconfcontents->len;
-
-                writeTarData(&stream, header, sizeof(header));
-                writeTarData(&stream, recoveryconfcontents->data, recoveryconfcontents->len);
-                if (padding)
-                    writeTarData(&stream, zerobuf, padding);
-            }
+                TarInsertRecoveryConf(&stream);            CloseTarFile(&stream);            break;
-- 
2.3.0




pgsql-hackers by date:

Previous
From: Joshua Elsasser
Date:
Subject: Re: Add pg_basebackup single tar output format
Next
From: Joshua Elsasser
Date:
Subject: [PATCH 2/6] pg_basebackup: factor out tar open/close code for reusability.