diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index 208df557b8..7f2df1d09b 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -211,11 +211,11 @@ $node->command_fails( 'pg_basebackup tar with long name fails'); unlink "$pgdata/$superlongname"; -# The following tests test symlinks. Windows doesn't have symlinks, so -# skip on Windows. +# The following tests are for symlinks. SKIP: { - skip "symlinks not supported on Windows", 18 if ($windows_os); + skip "symlinks not supported with this perl installation", 18 + if (!$symlink_support); # Move pg_replslot out of $pgdata and create a symlink to it. $node->stop; @@ -238,11 +238,12 @@ SKIP: # for the tablespace directories, which hopefully won't run afoul of # the 99 character length limit. my $shorter_tempdir = TestLib::tempdir_short . "/tempdir"; + my $realTsDir = TestLib::perl2host("$shorter_tempdir/tblspc1"); symlink "$tempdir", $shorter_tempdir; mkdir "$tempdir/tblspc1"; $node->safe_psql('postgres', - "CREATE TABLESPACE tblspc1 LOCATION '$shorter_tempdir/tblspc1';"); + "CREATE TABLESPACE tblspc1 LOCATION '$realTsDir';"); $node->safe_psql('postgres', "CREATE TABLE test1 (a int) TABLESPACE tblspc1;"); $node->command_ok([ 'pg_basebackup', '-D', "$tempdir/tarbackup2", '-Ft' ], @@ -292,18 +293,33 @@ SKIP: ], 'plain format with tablespaces succeeds with tablespace mapping'); ok(-d "$tempdir/tbackup/tblspc1", 'tablespace was relocated'); - opendir(my $dh, "$pgdata/pg_tblspc") or die; - ok( ( grep { - -l "$tempdir/backup1/pg_tblspc/$_" - and readlink "$tempdir/backup1/pg_tblspc/$_" eq - "$tempdir/tbackup/tblspc1" - } readdir($dh)), - "tablespace symlink was updated"); - closedir $dh; + + # This symlink check is not supported on Windows. Win32::Symlink works + # around this situation by using junction points (actually PostgreSQL + # approach on the problem), and -l is not able to detect that situation. + SKIP: + { + skip "symlink check not implemented on Windows", 1 + if ($windows_os); + opendir(my $dh, "$pgdata/pg_tblspc") or die; + ok( ( grep { + -l "$tempdir/backup1/pg_tblspc/$_" + and readlink "$tempdir/backup1/pg_tblspc/$_" eq + "$tempdir/tbackup/tblspc1" + } readdir($dh)), + "tablespace symlink was updated"); + closedir $dh; + } # Group access should be enabled on all backup files - ok(check_mode_recursive("$tempdir/backup1", 0750, 0640), - "check backup dir permissions"); + SKIP: + { + skip "unix-style permissions not supported on Windows", 1 + if ($windows_os); + + ok(check_mode_recursive("$tempdir/backup1", 0750, 0640), + "check backup dir permissions"); + } # Unlogged relation forks other than init should not be copied my ($tblspc1UnloggedBackupPath) = diff --git a/src/bin/pg_dump/t/010_dump_connstr.pl b/src/bin/pg_dump/t/010_dump_connstr.pl index abdb07c558..1fd8a78abc 100644 --- a/src/bin/pg_dump/t/010_dump_connstr.pl +++ b/src/bin/pg_dump/t/010_dump_connstr.pl @@ -5,7 +5,7 @@ use PostgresNode; use TestLib; use Test::More; -if ($^O eq 'msys' && `uname -or` =~ /^[2-9].*Msys/) +if ($TestLib::is_msys2) { plan skip_all => 'High bit name tests fail on Msys2'; } diff --git a/src/bin/pg_rewind/t/004_pg_xlog_symlink.pl b/src/bin/pg_rewind/t/004_pg_xlog_symlink.pl index 639eeb9c91..400d6d9b7d 100644 --- a/src/bin/pg_rewind/t/004_pg_xlog_symlink.pl +++ b/src/bin/pg_rewind/t/004_pg_xlog_symlink.pl @@ -7,9 +7,9 @@ use File::Copy; use File::Path qw(rmtree); use TestLib; use Test::More; -if ($windows_os) +if (!$symlink_support) { - plan skip_all => 'symlinks not supported on Windows'; + plan skip_all => 'symlinks not supported with this perl installation'; exit; } else diff --git a/src/test/perl/TestLib.pm b/src/test/perl/TestLib.pm index d579d5c177..329c656ed1 100644 --- a/src/test/perl/TestLib.pm +++ b/src/test/perl/TestLib.pm @@ -22,6 +22,7 @@ TestLib - helper module for writing PostgreSQL's C tests. # Miscellanea print "on Windows" if $TestLib::windows_os; + print "supports symlinks" if $TestLib::symlink_support; my $path = TestLib::perl2host($backup_dir); ok(check_mode_recursive($stream_dir, 0700, 0600), "check stream dir permissions"); @@ -84,10 +85,13 @@ our @EXPORT = qw( command_checks_all $windows_os + $symlink_support + $is_msys2 $use_unix_sockets ); -our ($windows_os, $use_unix_sockets, $tmp_check, $log_path, $test_logfile); +our ($windows_os, $is_msys2, $symlink_support, $use_unix_sockets, $tmp_check, + $log_path, $test_logfile); BEGIN { @@ -120,6 +124,32 @@ BEGIN Win32API::File->import(qw(createFile OsFHandleOpen CloseHandle)); } + # Check if this environment is MSYS2. + $is_msys2 = $^O eq 'msys' && `uname -or` =~ /^[2-9].*Msys/; + + # Check if this installation of perl running the tests has support + # for symlinks. Some installations of perl on Windows may provide + # an equivalent implementation based on junction points thanks to + # Win32::Symlink. Non-Windows platforms and MSYS2 are able to + # support this case. + if ($windows_os && !$is_msys2) + { + eval { require Win32::Symlink; }; + if ($@) + { + $symlink_support = 0; + } + else + { + $symlink_support = 1; + Win32::Symlink->import(qw(readlink symlink)); + } + } + else + { + $symlink_support = 1; + } + # Specifies whether to use Unix sockets for test setups. On # Windows we don't use them by default since it's not universally # supported, but it can be overridden if desired. @@ -133,6 +163,14 @@ BEGIN =over +=item C<$is_msys2> + +Set to true when running under MSYS2. + +=item C<$symlink_support> + +Set to true when running with an installation of perl that supports symlinks. + =item C<$windows_os> Set to true when running under Windows, except on Cygwin. diff --git a/doc/src/sgml/regress.sgml b/doc/src/sgml/regress.sgml index d98187c970..6fb68db7c1 100644 --- a/doc/src/sgml/regress.sgml +++ b/doc/src/sgml/regress.sgml @@ -775,6 +775,9 @@ make check PROVE_TESTS='t/001_test1.pl t/003_test3.pl' The TAP tests require the Perl module IPC::Run. This module is available from CPAN or an operating system package. + On Windows, Win32API::File is additionally + required, and Win32::Symlink is optional to be + able to run tests related to symlinks.