Skip pg_baseback long filename test if path too long on Windows
authorAndrew Dunstan <andrew@dunslane.net>
Thu, 6 Jul 2023 16:27:40 +0000 (12:27 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Thu, 6 Jul 2023 16:29:13 +0000 (12:29 -0400)
On Windows, it's sometimes difficult to create a file with a path longer
than 255 chars, and if it can be created it might not be seen by the
archiver. This can be triggered by the test for tar backups with
filenames greater than 100 bytes. So we skip that test if the path would
exceed 255.

Backpatch to all live branches.

Reviewed by Daniel Gustafsson

Discussion: https://postgr.es/m/666ac55b-3400-fb2c-2cea-0281bf36a53c@dunslane.net

src/bin/pg_basebackup/t/010_pg_basebackup.pl

index 8f2b26558b7b1695f4e23906240c53564e97afb1..d4d14c11bf2b64cf0bd8f7c51fea251a3041d723 100644 (file)
@@ -304,21 +304,23 @@ $node->command_fails(
    [ @pg_basebackup_defs, '-D', "$tempdir/backup_foo", '-Fp', "-Tfoo" ],
    '-T with invalid format fails');
 
-# Tar format doesn't support filenames longer than 100 bytes.
-# Create the test file via a short name directory so it doesn't blow the
-# Windows path limit.
-my $lftmp = PostgreSQL::Test::Utils::tempdir_short;
-dir_symlink "$pgdata", "$lftmp/pgdata";
 my $superlongname = "superlongname_" . ("x" x 100);
-my $superlongpath = "$lftmp/pgdata/$superlongname";
+# Tar format doesn't support filenames longer than 100 bytes.
+SKIP:
+{
+   my $superlongpath = "$pgdata/$superlongname";
 
-open my $file, '>', "$superlongpath"
-  or die "unable to create file $superlongpath";
-close $file;
-$node->command_fails(
-   [ @pg_basebackup_defs, '-D', "$tempdir/tarbackup_l1", '-Ft' ],
-   'pg_basebackup tar with long name fails');
-unlink "$superlongpath";
+   skip "File path too long", 1
+     if $windows_os && length($superlongpath) > 255;
+
+   open my $file, '>', "$superlongpath"
+     or die "unable to create file $superlongpath";
+   close $file;
+   $node->command_fails(
+       [ @pg_basebackup_defs, '-D', "$tempdir/tarbackup_l1", '-Ft' ],
+       'pg_basebackup tar with long name fails');
+   unlink "$superlongpath";
+}
 
 # The following tests are for symlinks.