Re: refactoring basebackup.c - Mailing list pgsql-hackers

From Justin Pryzby
Subject Re: refactoring basebackup.c
Date
Msg-id 20220311162911.GM28503@telsasoft.com
Whole thread Raw
In response to Re: refactoring basebackup.c  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Fri, Mar 11, 2022 at 10:19:29AM -0500, Robert Haas wrote:
> So I think we should just refuse this command. Patch for that attached.

Sounds right.

Also, I think the magic 8 for .gz should actually be a 7.

I'm not sure why it tests for ".gz" but not ".tar.gz", which would help to make
them all less magic.

commit 1fb1e21ba7a500bb2b85ec3e65f59130fcdb4a7e
Author: Justin Pryzby <pryzbyj@telsasoft.com>
Date:   Thu Mar 10 21:22:16 2022 -0600

    pg_basebackup: make magic numbers less magic
    
    The magic 8 for .gz should actually be a 7.
    
    .tar.gz
    1234567
    
    .tar.lz4
    .tar.zst
    12345678
    
    See d45099425, 751b8d23b, 7cf085f07.

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 9f3ecc60fbe..8dd9721323d 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1223,17 +1223,17 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
     is_tar = (archive_name_len > 4 &&
               strcmp(archive_name + archive_name_len - 4, ".tar") == 0);
 
-    /* Is this a gzip archive? */
-    is_tar_gz = (archive_name_len > 8 &&
-                 strcmp(archive_name + archive_name_len - 3, ".gz") == 0);
+    /* Is this a .tar.gz archive? */
+    is_tar_gz = (archive_name_len > 7 &&
+                 strcmp(archive_name + archive_name_len - 7, ".tar.gz") == 0);
 
-    /* Is this a LZ4 archive? */
+    /* Is this a .tar.lz4 archive? */
     is_tar_lz4 = (archive_name_len > 8 &&
-                  strcmp(archive_name + archive_name_len - 4, ".lz4") == 0);
+                  strcmp(archive_name + archive_name_len - 8, ".tar.lz4") == 0);
 
-    /* Is this a ZSTD archive? */
+    /* Is this a .tar.zst archive? */
     is_tar_zstd = (archive_name_len > 8 &&
-                   strcmp(archive_name + archive_name_len - 4, ".zst") == 0);
+                   strcmp(archive_name + archive_name_len - 8, ".tar.zst") == 0);
 
     /*
      * We have to parse the archive if (1) we're suppose to extract it, or if



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: role self-revocation
Next
From: Tom Lane
Date:
Subject: Re: role self-revocation