Msys2 tweaks for pg_validatebackup corruption test
authorAndrew Dunstan <andrew@dunslane.net>
Wed, 8 Apr 2020 21:50:55 +0000 (17:50 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Wed, 8 Apr 2020 21:50:55 +0000 (17:50 -0400)
1. Tell Msys2 not to mangle the tablespace map parameter
2. If rmdir doesn't work, fall back to trying unlink on the entry in
   pg_tblspc.

Discussion: https://postgr.es/m/7330a7c7-ce5f-9769-39a1-bdb0b32bb4a6@2ndQuadrant.com

src/bin/pg_validatebackup/t/003_corruption.pl

index 7a09d02e6c70eb303d0635e5c727ff92b4ecd6f9..09f8b982504ffeaa90387faf432ab64d9355d023 100644 (file)
@@ -16,6 +16,9 @@ $master->start;
 # Include a user-defined tablespace in the hopes of detecting problems in that
 # area.
 my $source_ts_path = TestLib::perl2host(TestLib::tempdir_short());
+my $source_ts_prefix = $source_ts_path;
+$source_ts_prefix =~ s!(^[A-Z]:/[^/]*)/.*!$1!;
+
 $master->safe_psql('postgres', <<EOM);
 CREATE TABLE x1 (a int);
 INSERT INTO x1 VALUES (111);
@@ -105,6 +108,10 @@ for my $scenario (@scenario)
                # Take a backup and check that it validates OK.
                my $backup_path = $master->backup_dir . '/' . $name;
                my $backup_ts_path = TestLib::perl2host(TestLib::tempdir_short());
+               # The tablespace map parameter confuses Msys2, which tries to mangle
+               # it. Tell it not to.
+               # See https://www.msys2.org/wiki/Porting/#filesystem-namespaces
+               local $ENV{MSYS2_ARG_CONV_EXCL} = $source_ts_prefix;
                $master->command_ok(['pg_basebackup', '-D', $backup_path, '--no-sync',
                                                        '-T', "${source_ts_path}=${backup_ts_path}"],
                                                        "base backup ok");
@@ -179,7 +186,14 @@ sub mutilate_missing_tablespace
        my $pathname = "$backup_path/pg_tblspc/$tsoid";
        if ($windows_os)
        {
-               rmdir($pathname) || die "$pathname: $!";
+               # rmdir works on some windows setups, unlink on others.
+               # Instead of trying to implement precise rules, just try one and then
+               # the other.
+               unless (rmdir($pathname))
+               {
+                       my $err = $!;
+                       unlink($pathname) || die "$pathname: rmdir: $err, unlink: $!";
+               }
        }
        else
        {