-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File::Find: fix "follow => 1" on Windows
File::Find's code expects unix-style paths and it manipulates them using basic string operations. That code is very fragile, and ideally we should make it use File::Spec, but that would involve rewriting almost the whole module. Instead, we made it convert backslashes to slashes and handle drive letters. Note from xenu: this commit was adapted from the PR linked in this blogpost[1]. I have squashed it, written the commit message and slightly modified the code. [1] - https://www.nu42.com/2021/09/canonical-paths-file-find-way-forward.html Fixes #19995
- Loading branch information
Showing
7 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!./perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use File::Find qw( find finddepth ); | ||
use File::Temp qw(); | ||
use Test::More; | ||
|
||
my $warn_msg; | ||
|
||
BEGIN { | ||
$SIG{'__WARN__'} = sub { | ||
$warn_msg = $_[0]; | ||
warn "# $_[0]"; | ||
return; | ||
} | ||
} | ||
|
||
sub test_find_correct_paths_with_follow { | ||
$warn_msg = ''; | ||
my $dir = File::Temp->newdir('file-find-XXXXXX', TMPDIR => 1, CLEANUP => 1); | ||
|
||
find( | ||
{ | ||
follow => 1, | ||
wanted => sub { return }, | ||
}, | ||
$dir, | ||
); | ||
|
||
unlike( | ||
$warn_msg, | ||
qr/Couldn't chdir/, | ||
'find: Derive absolute path correctly with follow => 1', | ||
); | ||
} | ||
|
||
sub test_finddepth_correct_paths_with_follow { | ||
$warn_msg = ''; | ||
my $dir = File::Temp->newdir('file-find-XXXXXX', TMPDIR => 1, CLEANUP => 1); | ||
|
||
finddepth( | ||
{ | ||
follow => 1, | ||
wanted => sub { return }, | ||
}, | ||
$dir, | ||
); | ||
|
||
unlike( | ||
$warn_msg, | ||
qr/Couldn't chdir/, | ||
'finddepth: Derive absolute path correctly with follow => 1', | ||
); | ||
} | ||
sub run { | ||
test_find_correct_paths_with_follow; | ||
test_finddepth_correct_paths_with_follow; | ||
done_testing; | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters