]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Consolidate methods for translating a Perl path to a Windows path.
authorNoah Misch <noah@leadboat.com>
Sat, 22 Jun 2019 03:34:23 +0000 (20:34 -0700)
committerNoah Misch <noah@leadboat.com>
Sat, 22 Jun 2019 03:47:34 +0000 (20:47 -0700)
This fixes some TAP suites when using msys Perl and a builddir located
in an msys mount point other than "/".  For example, builddir=/c/pg
exhibited the problem, since /c/pg falls in mount point "/c".
Back-patch to 9.6, where tests first started to perform such
translations.  In back branches, offer both new and old APIs.

Reviewed by Andrew Dunstan.

Discussion: https://postgr.es/m/20190610045838.GA238501@rfd.leadboat.com

src/test/perl/PostgresNode.pm
src/test/perl/TestLib.pm
src/test/recovery/t/014_unlogged_reinit.pl
src/test/recovery/t/017_shm.pl

index d1e3c36a2407f12fa8ff588c7728fe0e1a734281..c222b4fc915fa05c5abd5290f3fe33c4fb7a5499 100644 (file)
@@ -107,8 +107,7 @@ our @EXPORT = qw(
 our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
        $last_port_assigned, @all_nodes, $died);
 
-# Windows path to virtual file system root
-
+# For backward compatibility only.
 our $vfs_path = '';
 if ($Config{osname} eq 'msys')
 {
@@ -904,7 +903,7 @@ standby_mode=on
 sub enable_restoring
 {
        my ($self, $root_node) = @_;
-       my $path = $vfs_path . $root_node->archive_dir;
+       my $path = TestLib::perl2host($root_node->archive_dir);
        my $name = $self->name;
 
        print "### Enabling WAL restore for node \"$name\"\n";
@@ -933,7 +932,7 @@ standby_mode = on
 sub enable_archiving
 {
        my ($self) = @_;
-       my $path   = $vfs_path . $self->archive_dir;
+       my $path   = TestLib::perl2host($self->archive_dir);
        my $name   = $self->name;
 
        print "### Enabling WAL archiving for node \"$name\"\n";
index 8a29740743e9ee7b7ca8cd9e7439de5bc5bdf2c9..da7da60193d451b04d489d11df8c31892a5e4f7e 100644 (file)
@@ -164,22 +164,37 @@ sub tempdir_short
        return File::Temp::tempdir(CLEANUP => 1);
 }
 
-# Return the real directory for a virtual path directory under msys.
-# The directory  must exist. If it's not an existing directory or we're
-# not under msys, return the input argument unchanged.
-sub real_dir
+# Translate a Perl file name to a host file name.  Currently, this is a no-op
+# except for the case of Perl=msys and host=mingw32.  The subject need not
+# exist, but its parent directory must exist.
+sub perl2host
 {
-       my $dir = "$_[0]";
-       return $dir unless -d $dir;
-       return $dir unless $Config{osname} eq 'msys';
+       my ($subject) = @_;
+       return $subject unless $Config{osname} eq 'msys';
        my $here = cwd;
-       chdir $dir;
+       my $leaf;
+       if (chdir $subject)
+       {
+               $leaf = '';
+       }
+       else
+       {
+               $leaf = '/' . basename $subject;
+               my $parent = dirname $subject;
+               chdir $parent or die "could not chdir \"$parent\": $!";
+       }
 
        # this odd way of calling 'pwd -W' is the only way that seems to work.
-       $dir = qx{sh -c "pwd -W"};
+       my $dir = qx{sh -c "pwd -W"};
        chomp $dir;
        chdir $here;
-       return $dir;
+       return $dir . $leaf;
+}
+
+# For backward compatibility only.
+sub real_dir
+{
+       return perl2host(@_);
 }
 
 sub system_log
index 103c0a2b91ccdcfafd2f9d2b2470f48d67822edc..ee05e1a1ee11ced566d50d6ae93c554099b3a5f5 100644 (file)
@@ -30,7 +30,7 @@ ok(-f "$pgdata/$baseUnloggedPath",        'main fork in base exists');
 
 my $tablespaceDir = TestLib::tempdir;
 
-my $realTSDir = TestLib::real_dir($tablespaceDir);
+my $realTSDir = TestLib::perl2host($tablespaceDir);
 
 $node->safe_psql('postgres', "CREATE TABLESPACE ts1 LOCATION '$realTSDir'");
 $node->safe_psql('postgres',
index f16821d51fe97d3a0dc53f15f11d8e70d0eed4ea..7f10ff5225b13af55fb3c8c29f36b2114ff056bd 100644 (file)
@@ -12,14 +12,6 @@ use Time::HiRes qw(usleep);
 
 plan tests => 5;
 
-# See PostgresNode
-my $vfs_path = '';
-if ($Config{osname} eq 'msys')
-{
-       $vfs_path = `cd / && pwd -W`;
-       chomp $vfs_path;
-}
-
 my $tempdir = TestLib::tempdir;
 my $port;
 
@@ -103,10 +95,11 @@ log_ipcs();
 # Scenarios involving no postmaster.pid, dead postmaster, and a live backend.
 # Use a regress.c function to emulate the responsiveness of a backend working
 # through a CPU-intensive task.
+my $regress_shlib = TestLib::perl2host($ENV{REGRESS_SHLIB});
 $gnat->safe_psql('postgres', <<EOSQL);
 CREATE FUNCTION wait_pid(int)
    RETURNS void
-   AS '$vfs_path$ENV{REGRESS_SHLIB}'
+   AS '$regress_shlib'
    LANGUAGE C STRICT;
 EOSQL
 my $slow_query = 'SELECT wait_pid(pg_backend_pid())';