Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bedc1f0

Browse files
committed
Rework code defining default compression for dir/custom formats in pg_dump
As written, pg_dump would call twice parse_compress_specification() for the custom and directory formats to build a compression specification if no compression option is defined, as these formats should be compressed by default when compiled with zlib, or use no compression without zlib. This made the code logic quite confusing, and the first compression specification built would be incorrect before being overwritten by the second one. Rather than creating two compression specifications, this commit changes a bit the order of the checks for the compression options so as compression_algorithm_str is now set to a correct value for the custom and format directory when no compression option is defined. This makes the code easier to understand, as parse_compress_specification() is now called once for all the format, with or without user-specified compression methods. One comment was also confusing for the non-zlib case, so remove it while on it. This code has been introduced in 5e73a60 when adding support for compression specifications in pg_dump. Per discussion with Justin Pryzby and Georgios Kokolatos. Discussion: https://postgr.es/m/20230225050214.GH1653@telsasoft.com
1 parent 7b7fa85 commit bedc1f0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,21 @@ main(int argc, char **argv)
721721
if (archiveFormat == archNull)
722722
plainText = 1;
723723

724+
/*
725+
* Custom and directory formats are compressed by default with gzip when
726+
* available, not the others. If gzip is not available, no compression is
727+
* done by default.
728+
*/
729+
if ((archiveFormat == archCustom || archiveFormat == archDirectory) &&
730+
!user_compression_defined)
731+
{
732+
#ifdef HAVE_LIBZ
733+
compression_algorithm_str = "gzip";
734+
#else
735+
compression_algorithm_str = "none";
736+
#endif
737+
}
738+
724739
/*
725740
* Compression options
726741
*/
@@ -749,21 +764,6 @@ main(int argc, char **argv)
749764
pg_log_warning("compression option \"%s\" is not currently supported by pg_dump",
750765
"workers");
751766

752-
/*
753-
* Custom and directory formats are compressed by default with gzip when
754-
* available, not the others.
755-
*/
756-
if ((archiveFormat == archCustom || archiveFormat == archDirectory) &&
757-
!user_compression_defined)
758-
{
759-
#ifdef HAVE_LIBZ
760-
parse_compress_specification(PG_COMPRESSION_GZIP, NULL,
761-
&compression_spec);
762-
#else
763-
/* Nothing to do in the default case */
764-
#endif
765-
}
766-
767767
/*
768768
* If emitting an archive format, we always want to emit a DATABASE item,
769769
* in case --create is specified at pg_restore time.

0 commit comments

Comments
 (0)