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

From: Joshua Elsasser <josh(at)idealist(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Joshua Elsasser <josh(at)idealist(dot)org>
Subject: [PATCH 3/6] pg_basebackup: factor out code to add a recovery.conf file to the tar file.
Date: 2015-09-29 22:16:25
Message-ID: 1443564988-17928-4-git-send-email-josh@idealist.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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);
static void 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 relative to 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 empty blocks 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua Elsasser 2015-09-29 22:16:26 [PATCH 4/6] pg_basebackup: don't lose a zero-length file at the end of a tablespace.
Previous Message Joshua Elsasser 2015-09-29 22:16:24 [PATCH 2/6] pg_basebackup: factor out tar open/close code for reusability.