gflohr / file-globstar Goto Github PK
View Code? Open in Web Editor NEWGlobstar and gitignore style exclusion/ignore and inclusion lists
Home Page: http://www.guido-flohr.net/globstar-for-perl/
License: Other
Globstar and gitignore style exclusion/ignore and inclusion lists
Home Page: http://www.guido-flohr.net/globstar-for-perl/
License: Other
The code for File::Globstar::globstar
does not accept a directory even though the doc implies that it does. Instead, the second argument is $flags
to be pushed to bsd_glob
.
Please see the following discussion on StackOverflow.
https://stackoverflow.com/questions/56017474/fileglobstar-not-working-for-some-patterns
In the synopsis, the "parse string" example contains single quotes around patterns that are (probably) wrong.
If I invoke globstar('path/to/dir/**/*.txt')
without any glob flags, the result fails because globstar is passing $flags
:
# Bad. Returns 0 files
my @files = bsd_glob('pat/to/dir/subdir/*.txt', undef)
# Good. Returns files.=
my @files = bsd_glob('pat/to/dir/subdir/*.txt');
At least on my build of perl (5.34.1 in Debian Linux), bsd_glob()
will fail to find any files if it is called with an undef file.
I was able to fix it with this diff:
diff --git a/lib/File/Globstar.pm b/lib/File/Globstar.pm
index ba4108caf4..aaa77fe9fd 100644
--- a/perlmod/CPAN/perl5.34.1/lib/perl5/File/Globstar.pm
+++ b/perlmod/CPAN/perl5.34.1/lib/perl5/File/Globstar.pm
@@ -120,7 +120,7 @@ sub _globstar($$;$) {
$current .= '/';
# Expand until here.
- my @directories = bsd_glob $current, $flags;
+ my @directories = bsd_glob($current, (defined $flags ? $flags : ()));
# And search in every subdirectory;
my %found_dirs;
@@ -150,7 +150,7 @@ sub _globstar($$;$) {
return keys %found_files;
} elsif ('**' eq $pattern) {
my %found_files;
- foreach my $directory (bsd_glob $current, $flags) {
+ foreach my $directory (bsd_glob($current, (defined $flags ? $flags : ()))) {
$found_files{$directory . '/'} = 1;
foreach my $file (_find_all $directory) {
$found_files{$file} = 1;
@@ -163,7 +163,7 @@ sub _globstar($$;$) {
}
# Pattern without globstar. Just return the normal expansion.
- return bsd_glob $current, $flags;
+ return bsd_glob($current, (defined $flags ? $flags : ()));
}
sub globstar {
On windows, if you have files named:
dir_1/file1.txt
dir.2/file2.txt
then globstar('**/*.txt')
will find dir_1/file1.txt
but will not find dir.2/file2.txt
. This is because ultimately _globstar
will call bsd_glob('dir\\.2/*.txt')
which will not match anything.
You can fix this by exempting .
from the hand-rolled quotemeta()
embedded in _globstar
:
- # This is a quotemeta() that does not escape the slash and the
- # colon. Escaped slashes confuse bsd_glob() and escaping colons
+ # This is a quotemeta() that does not escape the slash, the
+ # colon, or period. Escaped slashes confuse bsd_glob() and escaping colons
# may make a full port to Windows harder.
- $current =~ s{([\x00-\x2e\x3b-\x40\x5b-\x5e\x60\x7b-\x7f])}{\\$1}g;
+ $current =~ s{([\x00-\x2d\x3b-\x40\x5b-\x5e\x60\x7b-\x7f])}{\\$1}g;
if ($directory ne '' && '/' ne substr $directory, -1, 1) {
$current .= '/';
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.