From 01e47d27c46956962e10c7f20e68690391b0c653 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:58:35 +0800 Subject: [PATCH] ar: warn if archive member isn't found (#500) * ar -p mode with no arguments prints all members of the archive to standard output * ar -p can be given explicit member names to print * If I type the wrong member name GNU ar gives me a warning an proceeds to print the next member argument * Example: "perl ar -p new.ar notfound asa" --> print warning on stderr for notfound not being found, then print content of archive member asa on stdout --- bin/ar | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/ar b/bin/ar index 31579551..eafd1974 100755 --- a/bin/ar +++ b/bin/ar @@ -179,10 +179,13 @@ exit 0; sub printMember { my ($name, $pAr, $verbose) = @_; - print "\n<$name>\n\n" if $verbose; - - # dump the data - print $pAr->{$name}[6]; + if (exists $pAr->{$name}) { + print "\n<$name>\n\n" if $verbose; + print $pAr->{$name}[6]; + } + else { + warn "entry not found in archive: '$name'\n"; + } } # writes a directory-style listing for the specified archive member