Skip to content

Commit a40dca8

Browse files
committed
Consolidate methods for translating a Perl path to a Windows path.
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
1 parent f7aebd7 commit a40dca8

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

src/test/perl/PostgresNode.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ our @EXPORT = qw(
107107
our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
108108
$last_port_assigned, @all_nodes, $died);
109109

110-
# Windows path to virtual file system root
111-
110+
# For backward compatibility only.
112111
our $vfs_path = '';
113112
if ($Config{osname} eq 'msys')
114113
{
@@ -904,7 +903,7 @@ standby_mode=on
904903
sub enable_restoring
905904
{
906905
my ($self, $root_node) = @_;
907-
my $path = $vfs_path . $root_node->archive_dir;
906+
my $path = TestLib::perl2host($root_node->archive_dir);
908907
my $name = $self->name;
909908

910909
print "### Enabling WAL restore for node \"$name\"\n";
@@ -933,7 +932,7 @@ standby_mode = on
933932
sub enable_archiving
934933
{
935934
my ($self) = @_;
936-
my $path = $vfs_path . $self->archive_dir;
935+
my $path = TestLib::perl2host($self->archive_dir);
937936
my $name = $self->name;
938937

939938
print "### Enabling WAL archiving for node \"$name\"\n";

src/test/perl/TestLib.pm

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,37 @@ sub tempdir_short
164164
return File::Temp::tempdir(CLEANUP => 1);
165165
}
166166

167-
# Return the real directory for a virtual path directory under msys.
168-
# The directory must exist. If it's not an existing directory or we're
169-
# not under msys, return the input argument unchanged.
170-
sub real_dir
167+
# Translate a Perl file name to a host file name. Currently, this is a no-op
168+
# except for the case of Perl=msys and host=mingw32. The subject need not
169+
# exist, but its parent directory must exist.
170+
sub perl2host
171171
{
172-
my $dir = "$_[0]";
173-
return $dir unless -d $dir;
174-
return $dir unless $Config{osname} eq 'msys';
172+
my ($subject) = @_;
173+
return $subject unless $Config{osname} eq 'msys';
175174
my $here = cwd;
176-
chdir $dir;
175+
my $leaf;
176+
if (chdir $subject)
177+
{
178+
$leaf = '';
179+
}
180+
else
181+
{
182+
$leaf = '/' . basename $subject;
183+
my $parent = dirname $subject;
184+
chdir $parent or die "could not chdir \"$parent\": $!";
185+
}
177186

178187
# this odd way of calling 'pwd -W' is the only way that seems to work.
179-
$dir = qx{sh -c "pwd -W"};
188+
my $dir = qx{sh -c "pwd -W"};
180189
chomp $dir;
181190
chdir $here;
182-
return $dir;
191+
return $dir . $leaf;
192+
}
193+
194+
# For backward compatibility only.
195+
sub real_dir
196+
{
197+
return perl2host(@_);
183198
}
184199

185200
sub system_log

src/test/recovery/t/014_unlogged_reinit.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
my $tablespaceDir = TestLib::tempdir;
3232

33-
my $realTSDir = TestLib::real_dir($tablespaceDir);
33+
my $realTSDir = TestLib::perl2host($tablespaceDir);
3434

3535
$node->safe_psql('postgres', "CREATE TABLESPACE ts1 LOCATION '$realTSDir'");
3636
$node->safe_psql('postgres',

src/test/recovery/t/017_shm.pl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
plan tests => 5;
1414

15-
# See PostgresNode
16-
my $vfs_path = '';
17-
if ($Config{osname} eq 'msys')
18-
{
19-
$vfs_path = `cd / && pwd -W`;
20-
chomp $vfs_path;
21-
}
22-
2315
my $tempdir = TestLib::tempdir;
2416
my $port;
2517

@@ -103,10 +95,11 @@ sub init_start
10395
# Scenarios involving no postmaster.pid, dead postmaster, and a live backend.
10496
# Use a regress.c function to emulate the responsiveness of a backend working
10597
# through a CPU-intensive task.
98+
my $regress_shlib = TestLib::perl2host($ENV{REGRESS_SHLIB});
10699
$gnat->safe_psql('postgres', <<EOSQL);
107100
CREATE FUNCTION wait_pid(int)
108101
RETURNS void
109-
AS '$vfs_path$ENV{REGRESS_SHLIB}'
102+
AS '$regress_shlib'
110103
LANGUAGE C STRICT;
111104
EOSQL
112105
my $slow_query = 'SELECT wait_pid(pg_backend_pid())';

0 commit comments

Comments
 (0)