Skip to content

Commit

Permalink
Merge pull request #397 from suihkulokki/fix-unstable
Browse files Browse the repository at this point in the history
Add support for .deb files which have control.tar.xz
  • Loading branch information
mlschroe committed Oct 20, 2017
2 parents da1e11c + 1ed947b commit 5e6c4a0
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions Build/Deb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ sub parse {
return $ret;
}

sub ungzip {
sub uncompress {
my $data = shift;
my $tool = shift;
local (*TMP, *TMP2);
open(TMP, "+>", undef) or die("could not open tmpfile\n");
syswrite TMP, $data;
Expand All @@ -189,13 +190,13 @@ sub ungzip {
die("fork: $!\n") unless defined $pid;
if (!$pid) {
open(STDIN, "<&TMP");
exec 'gunzip';
die("gunzip: $!\n");
exec($tool);
die("$tool: $!\n");
}
close(TMP);
$data = '';
1 while sysread(TMP2, $data, 1024, length($data)) > 0;
close(TMP2) || die("gunzip error");
close(TMP2) || die("$tool error");
return $data;
}

Expand Down Expand Up @@ -230,6 +231,7 @@ sub debq {
return ();
}
my $data = '';
my $decompressor = "gunzip";
sysread(DEBF, $data, 4096);
if (length($data) < 8+60) {
warn("$fn: not a debian package - header too short\n");
Expand All @@ -255,9 +257,14 @@ sub debq {
$data = substr($data, 8 + 60 + $len);
if (substr($data, 0, 16) ne 'control.tar.gz ' &&
substr($data, 0, 16) ne 'control.tar.gz/ ') {
warn("$fn: control.tar.gz is not second ar entry\n");
close DEBF unless ref $fn;
return ();
if (substr($data, 0, 16) eq 'control.tar.xz ' ||
substr($data, 0, 16) eq 'control.tar.xz/ ') {
$decompressor = "unxz";
} else {
warn("$fn: control.tar is not second ar entry\n");
close DEBF unless ref $fn;
return ();
}
}
$len = substr($data, 48, 10);
if (length($data) < 60+$len) {
Expand All @@ -271,13 +278,13 @@ sub debq {
close DEBF unless ref($fn);
$data = substr($data, 60, $len);
my $controlmd5 = Digest::MD5::md5_hex($data); # our header signature
if ($have_zlib) {
if ($have_zlib && $decompressor eq "gunzip") {
$data = Compress::Zlib::memGunzip($data);
} else {
$data = ungzip($data);
$data = uncompress($data, $decompressor);
}
if (!$data) {
warn("$fn: corrupt control.tar.gz file\n");
warn("$fn: corrupt control.tar file\n");
return ();
}
my $control;
Expand All @@ -287,7 +294,7 @@ sub debq {
my $len = oct('00'.substr($data, 124,12));
my $blen = ($len + 1023) & ~511;
if (length($data) < $blen) {
warn("$fn: corrupt control.tar.gz file\n");
warn("$fn: corrupt control.tar file\n");
return ();
}
if ($n eq './control' || $n eq "control") {
Expand Down Expand Up @@ -389,8 +396,11 @@ sub queryhdrmd5 {
}
$data = substr($data, 8 + 60 + $len);
if (substr($data, 0, 16) ne 'control.tar.gz ' &&
substr($data, 0, 16) ne 'control.tar.gz/ ') {
warn("$bin: control.tar.gz is not second ar entry\n");
substr($data, 0, 16) ne 'control.tar.gz/ ' &&
substr($data, 0, 16) ne 'control.tar.xz ' &&
substr($data, 0, 16) ne 'control.tar.xz/ ')
{
warn("$bin: control.tar is not second ar entry\n");
close F;
return undef;
}
Expand Down

0 comments on commit 5e6c4a0

Please sign in to comment.