stop needing file
authorjoeyh <joeyh@19660600-52fe-0310-9875-adc0d7a7b53c>
Tue, 2 Oct 2007 19:47:51 +0000 (19:47 +0000)
committerjoeyh <joeyh@19660600-52fe-0310-9875-adc0d7a7b53c>
Tue, 2 Oct 2007 19:47:51 +0000 (19:47 +0000)
delta-format.txt
pristine-tar

index 8227cec..5bca7cf 100644 (file)
@@ -4,7 +4,6 @@ version
        Currently "1.0".
 type
        Type of file this is a delta for ("tar" or "gz").
-       Defaults to "tar" if not present.
 
 
 For tar files, it contains:
index 9e52837..867bef2 100755 (executable)
@@ -54,6 +54,13 @@ use File::Temp;
 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;
 
@@ -154,7 +161,7 @@ sub gentar {
 
        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;
@@ -187,8 +194,13 @@ sub gendelta {
        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"),
@@ -197,6 +209,8 @@ sub gendelta {
                doit("zcat $tarball > $tempdir/origtarball");
                $tarball="$tempdir/origtarball";
        }
+       close IN;
+       exit;
        
        my $sourcedir="$tempdir/tmp";
        doit("mkdir $sourcedir");