Skip to content

Commit

Permalink
File::Find: support Win32 symlinks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tonycoz committed Dec 1, 2020
1 parent a0ced39 commit 0d00729
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
7 changes: 3 additions & 4 deletions ext/File-Find/lib/File/Find.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use 5.006;
use strict;
use warnings;
use warnings::register;
our $VERSION = '1.37';
our $VERSION = '1.38';
require Exporter;
require Cwd;

Expand Down Expand Up @@ -161,9 +161,8 @@ sub _find_opt {
$pre_process = $wanted->{preprocess};
$post_process = $wanted->{postprocess};
$no_chdir = $wanted->{no_chdir};
$full_check = $Is_Win32 ? 0 : $wanted->{follow};
$follow = $Is_Win32 ? 0 :
$full_check || $wanted->{follow_fast};
$full_check = $wanted->{follow};
$follow = $full_check || $wanted->{follow_fast};
$follow_skip = $wanted->{follow_skip};
$untaint = $wanted->{untaint};
$untaint_pat = $wanted->{untaint_pattern};
Expand Down
14 changes: 13 additions & 1 deletion ext/File-Find/t/find.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use Testing qw(
dir_path
file_path
);
use Errno ();

my %Expect_File = (); # what we expect for $_
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
Expand Down Expand Up @@ -247,7 +248,17 @@ create_file_ok( file_path('fb', $testing_basenames[0]) );
mkdir_ok( dir_path('fb', 'fba'), 0770 );
create_file_ok( file_path('fb', 'fba', $testing_basenames[1]) );
if ($symlink_exists) {
symlink_ok('../fb','fa/fsl');
if (symlink('../fb','fa/fsl')) {
pass("able to symlink from ../fb to fa/fsl");
}
else {
if ($^O eq "MSWin32" && ($! == &Errno::ENOSYS || $! == &Errno::EPERM)) {
$symlink_exists = 0;
}
else {
fail("able to symlink from ../fb to fa/fsl");
}
}
}
create_file_ok( file_path('fa', $testing_basenames[2]) );

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

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

Expand Down
2 changes: 1 addition & 1 deletion ext/File-Find/t/lib/Testing.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sub mkdir_ok($$;$) {
my ($dir, $mask) = @_[0..1];
my $msg = $_[2] || "able to mkdir: $dir";
ok( mkdir($dir, $mask), $msg )
or die("Unable to mkdir: $dir");
or die("Unable to mkdir $!: $dir");
}

sub symlink_ok($$;$) {
Expand Down
40 changes: 37 additions & 3 deletions ext/File-Find/t/taint.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!./perl -T
use strict;

BEGIN {
require File::Spec;
if ($ENV{PERL_CORE}) {
# May be doing dynamic loading while @INC is all relative
@INC = map { $_ = File::Spec->rel2abs($_); /(.*)/; $1 } @INC;
}

if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') {
# This is a hack - at present File::Find does not produce native names
# on Win32 or VMS, so force File::Spec to use Unix names.
# must be set *before* importing File::Find
require File::Spec::Unix;
@File::Spec::ISA = 'File::Spec::Unix';
}
require File::Find;
import File::Find;
}

use Test::More;
BEGIN {
plan(
Expand All @@ -16,6 +35,7 @@ use Testing qw(
dir_path
file_path
);
use Errno ();

my %Expect_File = (); # what we expect for $_
my %Expect_Name = (); # what we expect for $File::Find::name/fullname
Expand Down Expand Up @@ -169,8 +189,21 @@ create_file_ok( file_path('fb_taint', 'fb_ord') );
mkdir_ok( dir_path('fb_taint', 'fba'), 0770 );
create_file_ok( file_path('fb_taint', 'fba', 'fba_ord') );
SKIP: {
skip "Creating symlink", 1, unless $symlink_exists;
ok( symlink('../fb_taint','fa_taint/fsl'), 'Created symbolic link' );
skip "Creating symlink", 1, unless $symlink_exists;
if (symlink('../fb_taint','fa_taint/fsl')) {
pass('Created symbolic link' );
}
else {
my $error = 0 + $!;
if ($^O eq "MSWin32" &&
($error == &Errno::ENOSYS || $error == &Errno::EPERM)) {
$symlink_exists = 0;
skip "symbolic links not available", 1;
}
else {
fail('Created symbolic link');
}
}
}
create_file_ok( file_path('fa_taint', 'fa_ord') );

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

is(scalar keys %Expect_File, 0, 'Found all expected files');
is(scalar keys %Expect_File, 0, 'Found all expected files')
or diag "Not found " . join(" ", sort keys %Expect_File);

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

0 comments on commit 0d00729

Please sign in to comment.