Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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:59:38 +0000 (20:59 -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

index 3daf396dbe485195f5328e7722c9a1b1ffe714f9..ec5985623bc8e0b64e37960999814b8cf374cd19 100644 (file)
@@ -102,8 +102,7 @@ our @EXPORT = qw(
 our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
    $last_port_assigned, @all_nodes);
 
-# Windows path to virtual file system root
-
+# For backward compatibility only.
 our $vfs_path = '';
 if ($Config{osname} eq 'msys')
 {
@@ -844,7 +843,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";
@@ -872,7 +871,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 649fd821733f13a7e8d450a89d545b4d09047759..713a1214e711cd689ee2f27b530d3aeb3c4aa88b 100644 (file)
@@ -11,6 +11,7 @@ use strict;
 use warnings;
 
 use Config;
+use Cwd;
 use Exporter 'import';
 use File::Basename;
 use File::Spec;
@@ -145,6 +146,33 @@ sub tempdir_short
    return File::Temp::tempdir(CLEANUP => 1);
 }
 
+# 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 ($subject) = @_;
+   return $subject unless $Config{osname} eq 'msys';
+   my $here = cwd;
+   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.
+   my $dir = qx{sh -c "pwd -W"};
+   chomp $dir;
+   chdir $here;
+   return $dir . $leaf;
+}
+
 sub system_log
 {
    print("# Running: " . join(" ", @_) . "\n");