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);
# 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: $!";
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');
# 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: $!";
# Now check that the backup no longer verifies. We must use -n
command_ok_or_fails_like
command_checks_all
+ tar_portability_options
+
$windows_os
$is_msys2
$use_unix_sockets
=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