From 0cb2ef268d3ffab66e01546d9dbc5a6e4813be8a Mon Sep 17 00:00:00 2001
From: Hari Babu <kommi.haribabu@gmail.com>
Date: Tue, 12 Feb 2019 17:55:53 +1100
Subject: [PATCH] pg_basebackup Correct the existing directory permissions

During the backup in case if the directory already exists,
pg_basebackup completes the backup without verifying whether
the directory permissions are proper or not? Without this validation,
the user needs to correct the permissions before starting the server.
Instead of that, now pg_basebackup changes the permissions of the
existing data directory similar like the initdb command.
---
 src/bin/pg_basebackup/pg_basebackup.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 594d67c9e9..a07c896900 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -701,6 +701,12 @@ verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found)
 			/*
 			 * Exists, empty
 			 */
+			if (chmod(dirname, pg_dir_create_mode) != 0)
+			{
+				fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
+						progname, dirname, strerror(errno));
+				exit(1);
+			}
 			if (found)
 				*found = true;
 			return;
-- 
2.20.1.windows.1

