Skip to content

Commit d0d6226

Browse files
committed
Fix thinko coming from 000f3ad
pg_basebackup.c relies on the compression level to not be 0 to decide if compression should be used, but 000f3ad missed the fact that the default compression (Z_DEFAULT_COMPRESSION) is -1, which would be used if specifying --gzip without --compress. While on it, add some coverage for --gzip, as this is rather easy to miss. Reported-by: Christoph Berg Discussion: https://postgr.es/m/YdhRDMLjabtXOnhY@msg.df7cb.de
1 parent 27b77ec commit d0d6226

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ LogStreamerMain(logstreamer_param *param)
524524
stream.do_sync);
525525
else
526526
stream.walmethod = CreateWalTarMethod(param->xlog,
527-
(compresslevel > 0) ?
527+
(compresslevel != 0) ?
528528
COMPRESSION_GZIP : COMPRESSION_NONE,
529529
compresslevel,
530530
stream.do_sync);

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Fcntl qw(:seek);
1111
use PostgreSQL::Test::Cluster;
1212
use PostgreSQL::Test::Utils;
13-
use Test::More tests => 113;
13+
use Test::More tests => 115;
1414

1515
program_help_ok('pg_basebackup');
1616
program_version_ok('pg_basebackup');
@@ -630,7 +630,7 @@
630630
# Check ZLIB compression if available.
631631
SKIP:
632632
{
633-
skip "postgres was not built with ZLIB support", 3
633+
skip "postgres was not built with ZLIB support", 5
634634
if (!check_pg_config("#define HAVE_LIBZ 1"));
635635

636636
$node->command_ok(
@@ -641,12 +641,23 @@
641641
'--format', 't'
642642
],
643643
'pg_basebackup with --compress');
644+
$node->command_ok(
645+
[
646+
'pg_basebackup', '-D',
647+
"$tempdir/backup_gzip2", '--gzip',
648+
'--no-sync', '--format',
649+
't'
650+
],
651+
'pg_basebackup with --gzip');
644652

645653
# Verify that the stored files are generated with their expected
646654
# names.
647655
my @zlib_files = glob "$tempdir/backup_gzip/*.tar.gz";
648656
is(scalar(@zlib_files), 2,
649-
"two files created with gzip (base.tar.gz and pg_wal.tar.gz)");
657+
"two files created with --compress (base.tar.gz and pg_wal.tar.gz)");
658+
my @zlib_files2 = glob "$tempdir/backup_gzip2/*.tar.gz";
659+
is(scalar(@zlib_files2), 2,
660+
"two files created with --gzip (base.tar.gz and pg_wal.tar.gz)");
650661

651662
# Check the integrity of the files generated.
652663
my $gzip = $ENV{GZIP_PROGRAM};
@@ -655,7 +666,9 @@
655666
|| $gzip eq ''
656667
|| system_log($gzip, '--version') != 0);
657668

658-
my $gzip_is_valid = system_log($gzip, '--test', @zlib_files);
669+
my $gzip_is_valid =
670+
system_log($gzip, '--test', @zlib_files, @zlib_files2);
659671
is($gzip_is_valid, 0, "gzip verified the integrity of compressed data");
660672
rmtree("$tempdir/backup_gzip");
673+
rmtree("$tempdir/backup_gzip2");
661674
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy