From 0664792cd50aa911bef456b294327f76d7b92f2b Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Tue, 24 May 2022 04:09:41 +0200 Subject: [PATCH] manually push option arguments to array instead of using s@ By mixing s@ for --$foo-hook options and manual pushing in --hook-dir, it can happen that options get lost. Consider the following test: use Getopt::Long; my $arr = []; GetOptions( 'A=s@' => \$arr, 'B=s' => sub { push @{$arr}, $_[1]; } ); foreach my $hook (@{$arr}) { print "hook: $hook\n"; } This works fine: perl test.pl --A=a1 --B=b1 --A=a2 --B=b2 hook: a1 hook: b1 hook: a2 hook: b2 This misses b1: perl test.pl --B=b1 --A=a2 --B=b2 hook: a2 hook: b2 --- mmdebstrap | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index 2482eba..c4ebfbc 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -4284,11 +4284,19 @@ sub main() { sub { push @{ $options->{noop} }, 'no-merged-usr'; }, 'force-check-gpg' => sub { push @{ $options->{noop} }, 'force-check-gpg'; }, - 'setup-hook=s@' => \$options->{setup_hook}, - 'extract-hook=s@' => \$options->{extract_hook}, - 'essential-hook=s@' => \$options->{essential_hook}, - 'customize-hook=s@' => \$options->{customize_hook}, - 'hook-directory=s' => sub { + 'setup-hook=s' => sub { + push @{ $options->{setup_hook} }, $_[1]; + }, + 'extract-hook=s' => sub { + push @{ $options->{extract_hook} }, $_[1]; + }, + 'essential-hook=s' => sub { + push @{ $options->{essential_hook} }, $_[1]; + }, + 'customize-hook=s' => sub { + push @{ $options->{customize_hook} }, $_[1]; + }, + 'hook-directory=s' => sub { my ($opt_name, $opt_value) = @_; if (!-e $opt_value) { error "hook directory \"$opt_value\" does not exist";