Re: Refactoring of compression options in pg_basebackup - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Refactoring of compression options in pg_basebackup
Date
Msg-id CA+TgmoZ=xYuJ6g8M+k9kHsdPEGj83sabkQnyFdjH_f0V8L77SA@mail.gmail.com
Whole thread Raw
In response to Re: Refactoring of compression options in pg_basebackup  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Refactoring of compression options in pg_basebackup
List pgsql-hackers
On Thu, Jan 20, 2022 at 2:03 AM Michael Paquier <michael@paquier.xyz> wrote:
> Well, if no colon is specified, we still need to check if optarg
> is a pure integer if it does not match any of the supported methods,
> as --compress=0 should be backward compatible with no compression and
> --compress=1~9 should imply gzip, no?

Yes.

> Done this way, I hope.

This looks better, but this part could be switched around:

+ /*
+ * Check if the first part of the string matches with a supported
+ * compression method.
+ */
+ if (pg_strcasecmp(firstpart, "gzip") != 0 &&
+ pg_strcasecmp(firstpart, "none") != 0)
+ {
+ /*
+ * It does not match anything known, so check for the
+ * backward-compatible case of only an integer, where the implied
+ * compression method changes depending on the level value.
+ */
+ if (!option_parse_int(firstpart, "-Z/--compress", 0,
+   INT_MAX, levelres))
+ exit(1);
+
+ *methodres = (*levelres > 0) ?
+ COMPRESSION_GZIP : COMPRESSION_NONE;
+ return;
+ }
+
+ /* Supported method found. */
+ if (pg_strcasecmp(firstpart, "gzip") == 0)
+ *methodres = COMPRESSION_GZIP;
+ else if (pg_strcasecmp(firstpart, "none") == 0)
+ *methodres = COMPRESSION_NONE;

You don't need to test for gzip and none in two places each. Just make
the block with the "It does not match ..." comment the "else" clause
for this last part.

-- 
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Replace uses of deprecated Python module distutils.sysconfig
Next
From: Shawn Debnath
Date:
Subject: Re: MultiXact\SLRU buffers configuration