From d0d62262d34154965511cfda6b98609d27752d5a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Sat, 8 Jan 2022 09:12:21 +0900 Subject: [PATCH] Fix thinko coming from 000f3adf pg_basebackup.c relies on the compression level to not be 0 to decide if compression should be used, but 000f3adf 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 --- src/bin/pg_basebackup/pg_basebackup.c | 2 +- src/bin/pg_basebackup/t/010_pg_basebackup.pl | 21 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index f40a750774..aa43fc0924 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -524,7 +524,7 @@ LogStreamerMain(logstreamer_param *param) stream.do_sync); else stream.walmethod = CreateWalTarMethod(param->xlog, - (compresslevel > 0) ? + (compresslevel != 0) ? COMPRESSION_GZIP : COMPRESSION_NONE, compresslevel, stream.do_sync); diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index 194644a03e..872fec3d35 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -10,7 +10,7 @@ use File::Path qw(rmtree); use Fcntl qw(:seek); use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; -use Test::More tests => 113; +use Test::More tests => 115; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -630,7 +630,7 @@ note "Testing pg_basebackup with compression methods"; # Check ZLIB compression if available. SKIP: { - skip "postgres was not built with ZLIB support", 3 + skip "postgres was not built with ZLIB support", 5 if (!check_pg_config("#define HAVE_LIBZ 1")); $node->command_ok( @@ -641,12 +641,23 @@ SKIP: '--format', 't' ], 'pg_basebackup with --compress'); + $node->command_ok( + [ + 'pg_basebackup', '-D', + "$tempdir/backup_gzip2", '--gzip', + '--no-sync', '--format', + 't' + ], + 'pg_basebackup with --gzip'); # Verify that the stored files are generated with their expected # names. my @zlib_files = glob "$tempdir/backup_gzip/*.tar.gz"; is(scalar(@zlib_files), 2, - "two files created with gzip (base.tar.gz and pg_wal.tar.gz)"); + "two files created with --compress (base.tar.gz and pg_wal.tar.gz)"); + my @zlib_files2 = glob "$tempdir/backup_gzip2/*.tar.gz"; + is(scalar(@zlib_files2), 2, + "two files created with --gzip (base.tar.gz and pg_wal.tar.gz)"); # Check the integrity of the files generated. my $gzip = $ENV{GZIP_PROGRAM}; @@ -655,7 +666,9 @@ SKIP: || $gzip eq '' || system_log($gzip, '--version') != 0); - my $gzip_is_valid = system_log($gzip, '--test', @zlib_files); + my $gzip_is_valid = + system_log($gzip, '--test', @zlib_files, @zlib_files2); is($gzip_is_valid, 0, "gzip verified the integrity of compressed data"); rmtree("$tempdir/backup_gzip"); + rmtree("$tempdir/backup_gzip2"); }