v4-0001-Improve-tar-portability-logic-from-ebba64c0.patch

application/octet-stream

Filename: v4-0001-Improve-tar-portability-logic-from-ebba64c0.patch
Type: application/octet-stream
Part: 0
Message: Re: pg_waldump: support decoding of WAL inside tarfile

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v4-0001
Subject: Improve tar portability logic from ebba64c0.
File+
src/test/perl/PostgreSQL/Test/Utils.pm 12 9
From fe53cc6d93114a6700dc00a57795e53a0fa0a4ee Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 3 Apr 2026 12:03:56 +1300
Subject: [PATCH v4 1/1] Improve tar portability logic from ebba64c0.

* GNU and BSD tar both understand --format=ustar.
* Windows lacks /dev/null, but perl knows its local name.
* ustar format doesn't like large UID/GID values, so set them to 0.
* OpenBSD has its own tar which understands -F ustar.

Backpatch-through: 18
Co-authored-by: Thomas Munro <thomas.munro@gmail.com>
Co-authored-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/3676229.1775170250%40sss.pgh.pa.us
Discussion: https://postgr.es/m/CAA5RZ0tt89MgNi4-0F4onH%2B-TFSsysFjMM-tBc6aXbuQv5xBXw%40mail.gmail.com
---
 src/test/perl/PostgreSQL/Test/Utils.pm | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm
index 120999f6ac9..050037f0d93 100644
--- a/src/test/perl/PostgreSQL/Test/Utils.pm
+++ b/src/test/perl/PostgreSQL/Test/Utils.pm
@@ -1328,21 +1328,24 @@ sub tar_portability_options
 
 	# GNU tar typically produces gnu-format archives, which we can read fine.
 	# But some platforms configure it to default to posix/pax format, and
-	# apparently they enable --sparse too.  Override that.
-	if (system("$tar --format=ustar -c -O /dev/null >/dev/null 2>/dev/null")
+	# apparently they enable --sparse too.  BSD tar (libarchive) does something
+	# similar.
+	#
+	# ustar format supports UIDs only up to 2^21 - 1 (2097151).  Override
+	# owner/group to avoid failures on systems where the running user's UID/GID
+	# exceeds that limit.
+	my $devnull = File::Spec->devnull();
+	if (system("$tar --format=ustar --owner=0 --group=0 -c $devnull >$devnull 2>$devnull")
 		== 0)
 	{
-		push(@tar_p_flags, "--format=ustar");
+		push(@tar_p_flags, "--format=ustar", "--owner=0", "--group=0");
 	}
 
-	# bsdtar also archives sparse files by default, but it spells the switch
-	# to disable that differently.
-	if (system("$tar --no-read-sparse -c - /dev/null >/dev/null 2>/dev/null")
-		== 0)
+	# OpenBSD's tar also defaults to pax, but spells the switch differently.
+	if (system("$tar -F ustar -c $devnull >$devnull 2>$devnull"))
 	{
-		push(@tar_p_flags, "--no-read-sparse");
+		push(@tar_p_flags, "-F", "ustar");
 	}
-
 	return @tar_p_flags;
 }
 
-- 
2.50.1