diff --git a/src/bin/pg_verifybackup/t/003_corruption.pl b/src/bin/pg_verifybackup/t/003_corruption.pl index 882d75d9dc2..405ea793b68 100644 --- a/src/bin/pg_verifybackup/t/003_corruption.pl +++ b/src/bin/pg_verifybackup/t/003_corruption.pl @@ -13,6 +13,7 @@ use PostgreSQL::Test::Utils; use Test::More; my $tar = $ENV{TAR}; +my @tar_p_flags = tar_portability_options($tar); my $primary = PostgreSQL::Test::Cluster->new('primary'); $primary->init(allows_streaming => 1); @@ -154,8 +155,8 @@ for my $scenario (@scenario) # have a TAR program available. Note that this destructively modifies # the backup directory. if ( !$scenario->{'needs_unix_permissions'} - || !defined $tar - || $tar eq '') + && defined $tar + && $tar ne '') { my $tar_backup_path = $primary->backup_dir . '/tar_' . $name; mkdir($tar_backup_path) || die "mkdir $tar_backup_path: $!"; @@ -171,14 +172,23 @@ for my $scenario (@scenario) chdir($tspath) || die "chdir: $!"; command_ok( - [ $tar, '-cf', "$tar_backup_path/$tsoid.tar", '.' ]); + [ + $tar, @tar_p_flags, + '-cf' => "$tar_backup_path/$tsoid.tar", + '.' + ]); chdir($cwd) || die "chdir: $!"; rmtree($tspath); } # tar and remove pg_wal chdir($backup_path . '/pg_wal') || die "chdir: $!"; - command_ok([ $tar, '-cf', "$tar_backup_path/pg_wal.tar", '.' ]); + command_ok( + [ + $tar, @tar_p_flags, + '-cf' => "$tar_backup_path/pg_wal.tar", + '.' + ]); chdir($cwd) || die "chdir: $!"; rmtree($backup_path . '/pg_wal'); @@ -190,7 +200,12 @@ for my $scenario (@scenario) # Construct base.tar with what's left. chdir($backup_path) || die "chdir: $!"; - command_ok([ $tar, '-cf' => "$tar_backup_path/base.tar", '.' ]); + command_ok( + [ + $tar, @tar_p_flags, + '-cf' => "$tar_backup_path/base.tar", + '.' + ]); chdir($cwd) || die "chdir: $!"; command_fails_like( diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index ce1f6aa30c0..a268f0f1dd0 100644 --- a/src/bin/pg_waldump/t/001_basic.pl +++ b/src/bin/pg_waldump/t/001_basic.pl @@ -11,15 +11,7 @@ use Test::More; use List::Util qw(shuffle); my $tar = $ENV{TAR}; -my @tar_c_flags; - -# By default, bsdtar archives sparse files in GNU tar's --format=posix --sparse -# format, so pg_waldump can't find files that ZFS has decided to store with -# holes. Turn that off. -if (system("$tar --no-read-sparse -c - /dev/null > /dev/null") == 0) -{ - push(@tar_c_flags, "--no-read-sparse"); -} +my @tar_p_flags = tar_portability_options($tar); program_help_ok('pg_waldump'); program_version_ok('pg_waldump'); @@ -355,7 +347,7 @@ sub generate_archive # move into the WAL directory before archiving files my $cwd = getcwd; chdir($directory) || die "chdir: $!"; - command_ok([$tar, @tar_c_flags, $compression_flags, $archive, @files]); + command_ok([ $tar, @tar_p_flags, $compression_flags, $archive, @files ]); chdir($cwd) || die "chdir: $!"; } @@ -389,7 +381,7 @@ for my $scenario (@scenarios) SKIP: { skip "tar command is not available", 56 - if !defined $tar && $scenario->{'is_archive'}; + if (!defined $tar || $tar eq '') && $scenario->{'is_archive'}; skip "$scenario->{'compression_method'} compression not supported by this build", 56 if !$scenario->{'enabled'} && $scenario->{'is_archive'}; diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm index 163d9a4beb9..120999f6ac9 100644 --- a/src/test/perl/PostgreSQL/Test/Utils.pm +++ b/src/test/perl/PostgreSQL/Test/Utils.pm @@ -99,6 +99,8 @@ our @EXPORT = qw( command_ok_or_fails_like command_checks_all + tar_portability_options + $windows_os $is_msys2 $use_unix_sockets @@ -1304,6 +1306,48 @@ sub command_checks_all =pod +=item tar_portability_options(tar) + +Check for non-default options we need to give to tar to create +a tarfile we can decode (i.e., no "pax" extensions). +Not needed in tests that only use tar to read tarfiles. + +Returns options as an array. + +=cut + +sub tar_portability_options +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my ($tar) = @_; + + my @tar_p_flags = (); + + return @tar_p_flags if (!defined $tar || $tar eq ''); + + # GNU tar typically produces gnu-format archives, which we can read fine. + # But some platforms configure it to default to posix/pax format, and + # apparently they enable --sparse too. Override that. + if (system("$tar --format=ustar -c -O /dev/null >/dev/null 2>/dev/null") + == 0) + { + push(@tar_p_flags, "--format=ustar"); + } + + # bsdtar also archives sparse files by default, but it spells the switch + # to disable that differently. + if (system("$tar --no-read-sparse -c - /dev/null >/dev/null 2>/dev/null") + == 0) + { + push(@tar_p_flags, "--no-read-sparse"); + } + + return @tar_p_flags; +} + +=pod + =back =cut