[debhelper-devel] [debhelper] 01/15: Dh_Lib: Add new glob_expand method
Niels Thykier
nthykier at moszumanska.debian.org
Wed Jun 28 13:47:47 UTC 2017
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch glob-refactor
in repository debhelper.
commit 8da840f1264ba55830fc42ce056c846efe06d0d3
Author: Niels Thykier <niels at thykier.net>
Date: Tue Jun 27 15:47:09 2017 +0000
Dh_Lib: Add new glob_expand method
Signed-off-by: Niels Thykier <niels at thykier.net>
---
Debian/Debhelper/Dh_Lib.pm | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 49c37c8..ba5dd33 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -35,6 +35,7 @@ my %NAMED_COMPAT_LEVELS = (
use Errno qw(ENOENT);
use Exporter qw(import);
+use File::Glob qw(bsd_glob GLOB_CSH GLOB_NOMAGIC GLOB_TILDE);
use vars qw(@EXPORT %dh);
@EXPORT=qw(&init &doit &doit_noerror &complex_doit &verbose_print &error
&nonquiet_print &print_and_doit &print_and_doit_noerror
@@ -57,7 +58,9 @@ use vars qw(@EXPORT %dh);
&log_installed_files &buildarch &rename_path
&on_pkgs_in_parallel &on_selected_pkgs_in_parallel
&rm_files &make_symlink_raw_target &on_items_in_parallel
- XARGS_INSERT_PARAMS_HERE
+ XARGS_INSERT_PARAMS_HERE &glob_expand_error_handler_reject
+ &glob_expand_error_handler_warn_and_discard &glob_expand
+ &glob_expand_error_handler_silently_ignore
);
# The Makefile changes this if debhelper is installed in a PREFIX.
@@ -935,6 +938,47 @@ sub addsubstvar {
}
}
+sub _glob_expand_error_default_msg {
+ my ($pattern, $dir_ref) = @_;
+ my $dir_list = join(', ', map { escape_shell($_) } @{$dir_ref});
+ return "Cannot find (any matches for) \"${pattern}\" (tried in $dir_list)";
+}
+
+sub glob_expand_error_handler_reject {
+ my $msg = _glob_expand_error_default_msg(@_);
+ error("$msg\n");
+ return;
+}
+
+sub glob_expand_error_handler_warn_and_discard {
+ my $msg = _glob_expand_error_default_msg(@_);
+ warning("$msg\n");
+ return;
+}
+
+sub glob_expand_error_handler_silently_ignore {
+ return;
+}
+
+sub glob_expand {
+ my ($dir_ref, $error_handler, @patterns) = @_;
+ my @dirs = @{$dir_ref};
+ my @result;
+ for my $pattern (@patterns) {
+ my @m;
+ for my $dir (@dirs) {
+ @m = bsd_glob("$dir/$pattern", GLOB_CSH & ~(GLOB_NOMAGIC|GLOB_TILDE));
+ last if @m;# > 1 or (@m and (-l $m[0] or -e _));
+ }
+ if (not @m) {
+ $error_handler //= \&glob_expand_error_handler_reject;
+ $error_handler->($pattern, $dir_ref);
+ }
+ push(@result, @m);
+ }
+ return @result;
+}
+
# Reads in the specified file, one line at a time. splits on words,
# and returns an array of arrays of the contents.
# If a value is passed in as the second parameter, then glob
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list