From aee530f243ab371473d93e1c9edcd29a7c4c6b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 18 Nov 2022 23:43:56 +0100 Subject: [PATCH 1/5] Fix realpath for symlinks on windows. The realpath function does not work correctly on Windows for perl<=5.37.5. This fixes issue #258. --- t/filesystem.t | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/filesystem.t b/t/filesystem.t index 3b20acd..3024331 100644 --- a/t/filesystem.t +++ b/t/filesystem.t @@ -418,9 +418,11 @@ SKIP: { skip "symlink unavailable", 1 unless has_symlinks(); eval { symlink $file => $link }; ok( $link->lstat->size, "lstat" ); - - is( $link->realpath, $file->realpath, "realpath resolves symlinks" ); - + SKIP: { + skip "realpath of symlink not working correctly on Windows for perl <= 5.37.5" + if $^O eq "MSWin32" and "$]" <= 5.037005; + is( $link->realpath, $file->realpath, "realpath resolves symlinks" ); + } ok $link->remove, 'remove symbolic link'; ok $file->remove; From 74e55cdbae3f1a422870c1c8d93ea927ab409b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Sat, 19 Nov 2022 21:43:49 +0100 Subject: [PATCH 2/5] lstat->size returns zero on Windows This fixes issue #269. --- t/filesystem.t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/filesystem.t b/t/filesystem.t index 3024331..b07688d 100644 --- a/t/filesystem.t +++ b/t/filesystem.t @@ -417,7 +417,12 @@ SKIP: { $file->spew("Hello World\n"); skip "symlink unavailable", 1 unless has_symlinks(); eval { symlink $file => $link }; - ok( $link->lstat->size, "lstat" ); + if ($^O eq "MSWin32") { + ok( $link->lstat->size == 0, "lstat->size returns zero on Windows" ); + } + else { + ok( $link->lstat->size, "lstat->size returns nonzero" ); + } SKIP: { skip "realpath of symlink not working correctly on Windows for perl <= 5.37.5" if $^O eq "MSWin32" and "$]" <= 5.037005; From 9e833f09bb7d410f692ed0fe40a08611830a59e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Sat, 19 Nov 2022 22:25:55 +0100 Subject: [PATCH 3/5] Fix forward slashes in symlink target on Windows This fixes issue #271 --- t/symlinks.t | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/t/symlinks.t b/t/symlinks.t index 9e1a6f5..df907f4 100644 --- a/t/symlinks.t +++ b/t/symlinks.t @@ -19,12 +19,16 @@ subtest "relative symlinks with updir" => sub { my $foo = $td->child(qw/tmp foo/)->touch; my $bar = $td->child(qw/tmp tmp2 bar/); - symlink "../foo", $bar or die "Failed to symlink: $!\n"; + my $relpath = "../foo"; + # Account for a bug in Win32 API, see https://github.com/Perl/perl5/issues/20506 + # for more information + $relpath = "..\\foo" if $^O eq "MSWin32"; + symlink $relpath, $bar or die "Failed to symlink: $!\n"; ok -f $foo, "it's a file"; ok -l $bar, "it's a link"; - is readlink $bar, "../foo", "the link seems right"; + is readlink $bar, $relpath, "the link seems right"; is abs_path($bar), $foo, "abs_path gets's it right"; is $bar->realpath, $foo, "realpath get's it right"; From 3f71bf6a98d501685a637bc7ceaeb81726f6a915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Sun, 20 Nov 2022 12:06:16 +0100 Subject: [PATCH 4/5] Don't use forward slashes in a relative symlink target Don't use forward slashes in a relative symlink target on Windows. For more information see issue #271. This fixes issue #273. --- t/recurse.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/t/recurse.t b/t/recurse.t index f40c3db..d760b18 100644 --- a/t/recurse.t +++ b/t/recurse.t @@ -107,7 +107,13 @@ subtest 'with symlinks' => sub { path($_)->touchpath for @tree; - symlink path( 'cccc', 'eeee' ), path('pppp'); + if ($^O eq "MSWin32") { + # need to use backward slashes in relative symlink target on MSWin32 + symlink 'cccc\eeee', path('pppp'); + } + else { + symlink path( 'cccc', 'eeee' ), path('pppp'); + } symlink path('aaaa.txt'), path('qqqq.txt'); subtest 'no follow' => sub { From 0bf86581b1acfaf9a6b0e115ddb331e5a57d9a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Tue, 6 Dec 2022 13:42:37 +0100 Subject: [PATCH 5/5] Absolute targets in symlink directories Absolute targets in symlink directories does not work on MSWin32 yet. See --- t/rel-abs.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/rel-abs.t b/t/rel-abs.t index af6970b..37711b6 100644 --- a/t/rel-abs.t +++ b/t/rel-abs.t @@ -111,7 +111,8 @@ subtest "relative on absolute paths with symlinks" => sub { plan skip_all => "No symlink support" unless has_symlinks(); - + plan skip_all => "Absolute paths in symlink directory targets not working on MSWin32 for perl<5.38" + if $^O eq "MSWin32" and "$]" < 5.038000; my ( $path, $base, $expect ); # (a) symlink in common path