Skip to content

Commit 0d00729

Browse files
committed
File::Find: support Win32 symlinks
find.t, taint.t: check that symlink() works under the current permissions/filesystem rather than assuming it will work find.t: since symlinks are now available, an earlier test block set $FileFileTests_OK, and the tests in this Win32 block don't use either of the follow options, which is required for fast file tests. taint.t: ensure we get "/" separated names to match File::Find's output
1 parent a0ced39 commit 0d00729

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

ext/File-Find/lib/File/Find.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use 5.006;
33
use strict;
44
use warnings;
55
use warnings::register;
6-
our $VERSION = '1.37';
6+
our $VERSION = '1.38';
77
require Exporter;
88
require Cwd;
99

@@ -161,9 +161,8 @@ sub _find_opt {
161161
$pre_process = $wanted->{preprocess};
162162
$post_process = $wanted->{postprocess};
163163
$no_chdir = $wanted->{no_chdir};
164-
$full_check = $Is_Win32 ? 0 : $wanted->{follow};
165-
$follow = $Is_Win32 ? 0 :
166-
$full_check || $wanted->{follow_fast};
164+
$full_check = $wanted->{follow};
165+
$follow = $full_check || $wanted->{follow_fast};
167166
$follow_skip = $wanted->{follow_skip};
168167
$untaint = $wanted->{untaint};
169168
$untaint_pat = $wanted->{untaint_pattern};

ext/File-Find/t/find.t

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use Testing qw(
3434
dir_path
3535
file_path
3636
);
37+
use Errno ();
3738

3839
my %Expect_File = (); # what we expect for $_
3940
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
@@ -247,7 +248,17 @@ create_file_ok( file_path('fb', $testing_basenames[0]) );
247248
mkdir_ok( dir_path('fb', 'fba'), 0770 );
248249
create_file_ok( file_path('fb', 'fba', $testing_basenames[1]) );
249250
if ($symlink_exists) {
250-
symlink_ok('../fb','fa/fsl');
251+
if (symlink('../fb','fa/fsl')) {
252+
pass("able to symlink from ../fb to fa/fsl");
253+
}
254+
else {
255+
if ($^O eq "MSWin32" && ($! == &Errno::ENOSYS || $! == &Errno::EPERM)) {
256+
$symlink_exists = 0;
257+
}
258+
else {
259+
fail("able to symlink from ../fb to fa/fsl");
260+
}
261+
}
251262
}
252263
create_file_ok( file_path('fa', $testing_basenames[2]) );
253264

@@ -880,6 +891,7 @@ if ($^O eq 'MSWin32') {
880891
dir_path('fb') => 1,
881892
dir_path('fba') => 1);
882893

894+
$FastFileTests_OK = 0;
883895
File::Find::find( {wanted => \&wanted_File_Dir}, topdir('fa'));
884896
is( scalar(keys %Expect_File), 0, "Got no files, as expected" );
885897

ext/File-Find/t/lib/Testing.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sub mkdir_ok($$;$) {
2828
my ($dir, $mask) = @_[0..1];
2929
my $msg = $_[2] || "able to mkdir: $dir";
3030
ok( mkdir($dir, $mask), $msg )
31-
or die("Unable to mkdir: $dir");
31+
or die("Unable to mkdir $!: $dir");
3232
}
3333

3434
sub symlink_ok($$;$) {

ext/File-Find/t/taint.t

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
#!./perl -T
22
use strict;
3+
4+
BEGIN {
5+
require File::Spec;
6+
if ($ENV{PERL_CORE}) {
7+
# May be doing dynamic loading while @INC is all relative
8+
@INC = map { $_ = File::Spec->rel2abs($_); /(.*)/; $1 } @INC;
9+
}
10+
11+
if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') {
12+
# This is a hack - at present File::Find does not produce native names
13+
# on Win32 or VMS, so force File::Spec to use Unix names.
14+
# must be set *before* importing File::Find
15+
require File::Spec::Unix;
16+
@File::Spec::ISA = 'File::Spec::Unix';
17+
}
18+
require File::Find;
19+
import File::Find;
20+
}
21+
322
use Test::More;
423
BEGIN {
524
plan(
@@ -16,6 +35,7 @@ use Testing qw(
1635
dir_path
1736
file_path
1837
);
38+
use Errno ();
1939

2040
my %Expect_File = (); # what we expect for $_
2141
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
@@ -169,8 +189,21 @@ create_file_ok( file_path('fb_taint', 'fb_ord') );
169189
mkdir_ok( dir_path('fb_taint', 'fba'), 0770 );
170190
create_file_ok( file_path('fb_taint', 'fba', 'fba_ord') );
171191
SKIP: {
172-
skip "Creating symlink", 1, unless $symlink_exists;
173-
ok( symlink('../fb_taint','fa_taint/fsl'), 'Created symbolic link' );
192+
skip "Creating symlink", 1, unless $symlink_exists;
193+
if (symlink('../fb_taint','fa_taint/fsl')) {
194+
pass('Created symbolic link' );
195+
}
196+
else {
197+
my $error = 0 + $!;
198+
if ($^O eq "MSWin32" &&
199+
($error == &Errno::ENOSYS || $error == &Errno::EPERM)) {
200+
$symlink_exists = 0;
201+
skip "symbolic links not available", 1;
202+
}
203+
else {
204+
fail('Created symbolic link');
205+
}
206+
}
174207
}
175208
create_file_ok( file_path('fa_taint', 'fa_ord') );
176209

@@ -201,7 +234,8 @@ delete @Expect_Dir{ dir_path('fb_taint'), dir_path('fba') } unless $symlink_exis
201234
File::Find::find( {wanted => \&wanted_File_Dir_prune, untaint => 1,
202235
untaint_pattern => qr|^(.+)$|}, topdir('fa_taint') );
203236

204-
is(scalar keys %Expect_File, 0, 'Found all expected files');
237+
is(scalar keys %Expect_File, 0, 'Found all expected files')
238+
or diag "Not found " . join(" ", sort keys %Expect_File);
205239

206240
# don't untaint at all, should die
207241
%Expect_File = ();

0 commit comments

Comments
 (0)