diff options
Diffstat (limited to 'src/bin/pg_basebackup')
-rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 9 | ||||
-rw-r--r-- | src/bin/pg_basebackup/t/010_pg_basebackup.pl | 14 | ||||
-rw-r--r-- | src/bin/pg_basebackup/t/020_pg_receivewal.pl | 14 | ||||
-rw-r--r-- | src/bin/pg_basebackup/walmethods.c | 6 |
4 files changed, 35 insertions, 8 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 8610fe8a1a8..32b41e313cc 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -27,6 +27,7 @@ #endif #include "access/xlog_internal.h" +#include "common/file_perm.h" #include "common/file_utils.h" #include "common/string.h" #include "fe_utils/string_utils.h" @@ -629,7 +630,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier) PQserverVersion(conn) < MINIMUM_VERSION_FOR_PG_WAL ? "pg_xlog" : "pg_wal"); - if (pg_mkdir_p(statusdir, S_IRWXU) != 0 && errno != EEXIST) + if (pg_mkdir_p(statusdir, pg_dir_create_mode) != 0 && errno != EEXIST) { fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"), @@ -685,7 +686,7 @@ verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found) /* * Does not exist, so create */ - if (pg_mkdir_p(dirname, S_IRWXU) == -1) + if (pg_mkdir_p(dirname, pg_dir_create_mode) == -1) { fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"), @@ -1129,7 +1130,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) tarCreateHeader(header, "recovery.conf", NULL, recoveryconfcontents->len, - 0600, 04000, 02000, + pg_file_create_mode, 04000, 02000, time(NULL)); padding = ((recoveryconfcontents->len + 511) & ~511) - recoveryconfcontents->len; @@ -1441,7 +1442,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) * Directory */ filename[strlen(filename) - 1] = '\0'; /* Remove trailing slash */ - if (mkdir(filename, S_IRWXU) != 0) + if (mkdir(filename, pg_dir_create_mode) != 0) { /* * When streaming WAL, pg_wal (or pg_xlog for pre-9.6 diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index afb392dbb39..ac5bb99f1b8 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -6,7 +6,7 @@ use File::Basename qw(basename dirname); use File::Path qw(rmtree); use PostgresNode; use TestLib; -use Test::More tests => 104; +use Test::More tests => 105; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -16,6 +16,9 @@ my $tempdir = TestLib::tempdir; my $node = get_new_node('main'); +# Set umask so test directories and files are created with default permissions +umask(0077); + # Initialize node without replication settings $node->init(extra => [ '--data-checksums' ]); $node->start; @@ -94,6 +97,15 @@ $node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup", '-X', 'none' ], 'pg_basebackup runs'); ok(-f "$tempdir/backup/PG_VERSION", 'backup was created'); +# Permissions on backup should be default +SKIP: +{ + skip "unix-style permissions not supported on Windows", 1 if ($windows_os); + + ok(check_mode_recursive("$tempdir/backup", 0700, 0600), + "check backup dir permissions"); +} + # Only archive_status directory should be copied in pg_wal/. is_deeply( [ sort(slurp_dir("$tempdir/backup/pg_wal/")) ], diff --git a/src/bin/pg_basebackup/t/020_pg_receivewal.pl b/src/bin/pg_basebackup/t/020_pg_receivewal.pl index 64e3a35a87b..19c106d9f59 100644 --- a/src/bin/pg_basebackup/t/020_pg_receivewal.pl +++ b/src/bin/pg_basebackup/t/020_pg_receivewal.pl @@ -2,12 +2,15 @@ use strict; use warnings; use TestLib; use PostgresNode; -use Test::More tests => 18; +use Test::More tests => 19; program_help_ok('pg_receivewal'); program_version_ok('pg_receivewal'); program_options_handling_ok('pg_receivewal'); +# Set umask so test directories and files are created with default permissions +umask(0077); + my $primary = get_new_node('primary'); $primary->init(allows_streaming => 1); $primary->start; @@ -56,3 +59,12 @@ $primary->command_ok( [ 'pg_receivewal', '-D', $stream_dir, '--verbose', '--endpos', $nextlsn, '--synchronous', '--no-loop' ], 'streaming some WAL with --synchronous'); + +# Permissions on WAL files should be default +SKIP: +{ + skip "unix-style permissions not supported on Windows", 1 if ($windows_os); + + ok(check_mode_recursive($stream_dir, 0700, 0600), + "check stream dir permissions"); +} diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index b4558a01847..267a40debbf 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -22,6 +22,7 @@ #endif #include "pgtar.h" +#include "common/file_perm.h" #include "common/file_utils.h" #include "receivelog.h" @@ -89,7 +90,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ * does not do any system calls to fsync() to make changes permanent on * disk. */ - fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR); + fd = open(tmppath, O_WRONLY | O_CREAT | PG_BINARY, pg_file_create_mode); if (fd < 0) return NULL; @@ -534,7 +535,8 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ * We open the tar file only when we first try to write to it. */ tar_data->fd = open(tar_data->tarfilename, - O_WRONLY | O_CREAT | PG_BINARY, S_IRUSR | S_IWUSR); + O_WRONLY | O_CREAT | PG_BINARY, + pg_file_create_mode); if (tar_data->fd < 0) return NULL; |