On Mon, Jun 29, 2020 at 04:56:16PM +0900, Michael Paquier wrote: > On Fri, Jun 26, 2020 at 02:00:37PM +0200, Peter Eisentraut wrote: >> We should be more accurate about things like this: >> >> +# The following tests test symlinks. Windows may not have symlinks, so >> +# skip there. >> >> The issue isn't whether Windows has symlinks, since all versions of Windows >> supported by PostgreSQL do (AFAIK). The issue is only whether the Perl >> installation that runs the tests has symlink support. And that is only >> necessary if the test itself wants to create or inspect symlinks. For >> example, there are existing tests involving tablespaces that work just fine >> on Windows. > > Check. Indeed that sounds confusing.
Attached is an updated patch, where I have tried to use a better wording in all the code paths involved. >> Relatedly, your patch ends up skipping the tests on MSYS2, even though Perl >> supports symlinks there out of the box. > > Do you think that it would be enough to use what Andrew has mentioned > in [1]? I don't have a MSYS2 installation, so I am unfortunately not > able to confirm that, but I would just move the check to TestLib.pm > and save it in an extra variable. Added an extra $is_msys2 to track that in TestLib.pm. One thing I am not sure of though: Win32::Symlink fails to work properly with -l, but is that the case with MSYS2? If that's able to work, it would be possible to not skip the following test but I have taken the most careful approach for now: + # 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) Thanks, -- Michael
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<prove> 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' <para> The TAP tests require the Perl module <literal>IPC::Run</literal>. This module is available from CPAN or an operating system package. + On Windows, <literal>Win32API::File</literal> is additionally + required, and <literal>Win32::Symlink</literal> is optional to be + able to run tests related to symlinks. </para> <para>
signature.asc
Description: PGP signature