use File::Path;
use Getopt::Long;
+# magic identification
+use constant GZIP_ID1 => 0x1F;
+use constant GZIP_ID2 => 0x8B;
+
+# compression methods, 0x00-0x07 are reserved
+use constant GZIP_METHOD_DEFLATE => 0x08;
+
my $verbose=0;
my $debug=0;
open (IN, "$tempdir/version") || die "delta lacks version number ($!)";
my $version=<IN>;
- if ($version >= 2) {
+ if ($version >= 2 || $version < 1.1) {
die "delta is version $version, not supported\n";
}
close IN;
my $tempdir=tempdir();
my @files=qw(delta manifest version type);
- my $file=`LANG=C file $tarball`;
- if ($file=~/: gzip compressed data/) {
+ # Check to see if it's compressed.
+ open (IN, "<", $tarball) || die "Cannot read $tarball: $!\n";
+ my ($chars, $id1, $id2, $method);
+ if (read(IN, $chars, 10) == 10 &&
+ (($id1, $id2, $method) = unpack("CCC", $chars)) &&
+ $id1 == GZIP_ID1 && $id2 == GZIP_ID2 &&
+ $method == GZIP_METHOD_DEFLATE) {
doit("pristine-gz",
($verbose ? "-v" : "--no-verbose"),
($debug ? "-d" : "--no-debug"),
doit("zcat $tarball > $tempdir/origtarball");
$tarball="$tempdir/origtarball";
}
+ close IN;
+ exit;
my $sourcedir="$tempdir/tmp";
doit("mkdir $sourcedir");