Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tar: fail early for bad options #978

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions bin/tar
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,13 @@ use IO::File;
use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

use vars qw($opt);

my $Program = basename($0);

BEGIN
{
$opt = 'ctxvmf:';
eval { require Compress::Zlib };
if ($@)
{
warn "No decompression available: $@\n";
}
else
{
Compress::Zlib->import;
$opt .= 'zZ';
}
}

my %opt;
getopts($opt,\%opt);
getopts('ctxvmf:Zz', \%opt) or do {
warn "usage: tar {-tx} [-mvZz] [-f archive] [file ...]\n";
exit EX_FAILURE;
};

sub fatal
{
Expand Down Expand Up @@ -225,7 +211,8 @@ else

if ($opt{'z'} || $opt{'Z'})
{
# quick and dirty till we sort out Compress::Zlib
eval { require Compress::Zlib } or fatal('Compress::Zlib not found');
Compress::Zlib->import;
my $gz = gzopen($fh, 'rb') or fatal("Cannot gzopen: $Compress::Zlib::gzerrno");
$read = sub { $gz->gzread($_[0],$_[1]) < 0 ? $Compress::Zlib::gzerrno : 0 };
}
Expand Down
Loading