From 021f7fca9d936870b20d648a1b6c0cf11ce2f709 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 26 May 2023 05:23:29 -0400 Subject: sbolint: handle extra dots in tarball filenames (e.g. foo.bar.tar.gz). --- sbolint | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sbolint b/sbolint index aff73de..406dd1e 100755 --- a/sbolint +++ b/sbolint @@ -484,14 +484,25 @@ sub check_tarball_mime { ); (my $basename = $file) =~ s,.*/,,; - my (undef, $ext) = split /\./, $basename, 2; + if($basename =~ /^\./) { + log_error("$file: tarball filename begins with a . (hidden, WTF?)"); + return; + } + my $ext; + if($basename =~ /\.(tar(?:\.(?:gz|bz2|xz))?)$/) { + $ext = $1; + } else { + log_error("$file: bad tarball filename, not .tar or .tar.(gz|bz2|xz), will be rejected by upload form"); + return; + } + + warn "\$basename is \"$basename\", \$ext is \"$ext\""; + my $mime = `file --brief --mime-type $file`; chomp $mime; if(!grep { $_ eq $mime } values %types) { log_error("$file is not a tarball (mime type is '$mime')"); - } elsif(!$ext) { - log_error("$file: filename has no extension (will be rejected by upload form)"); } elsif($types{$ext} ne $mime) { log_error("$file mime type '$mime' doesn't match filename (should be $types{$ext})"); } elsif($ext ne 'tar') { -- cgit v1.2.3