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
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers