From: Cyril Brulebois Date: Fri, 1 Feb 2008 23:35:07 +0000 (+0000) Subject: Add bz2 detection, spawn pristine-bz2 when needed. X-Git-Tag: 0.8~8^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6a5ebb611d8faae8eff832ceac264683371521ae;p=tools%2Fpristine-tar.git Add bz2 detection, spawn pristine-bz2 when needed. --- diff --git a/pristine-tar b/pristine-tar index 14f2de1..1f1a48a 100755 --- a/pristine-tar +++ b/pristine-tar @@ -90,10 +90,10 @@ Don't clean up the temporary directory on exit. =head1 LIMITATIONS -Only tar.gz files and .tar files are currently supported; there's -currently no support for .tar.bz2. +Only .tar, .tar.gz, and .tar.bz2 files are currently supported; .tar.bz2 +support is experimental, see pristine-bz2(1). -It could fail on certian spectacularly strange files. If it fails, it will +It could fail on certain spectacularly strange files. If it fails, it will fail during creation of the delta, since the delta is tested to make sure it reproduces the pristine tarball. @@ -121,10 +121,15 @@ use Cwd qw{getcwd abs_path}; # magic identification use constant GZIP_ID1 => 0x1F; use constant GZIP_ID2 => 0x8B; +use constant BZIP2_ID1 => 0x42; +use constant BZIP2_ID2 => 0x5a; # compression methods, 0x00-0x07 are reserved use constant GZIP_METHOD_DEFLATE => 0x08; +# compression methods, 'h' for Bzip2 ('H'uffman coding), '0' for Bzip1 (deprecated) +use constant BZIP2_METHOD_HUFFMAN => 0x68; + my $verbose=0; my $debug=0; my $keep=0; @@ -333,7 +338,7 @@ sub gentar { } recreatetarball($tempdir, getcwd, clobber_source => 0, %opts); - my $out=(-e "$tempdir/wrapper") ? $tarball.".tmp" : $tarball; + my $out=(-e "$tempdir/wrapper" || -e "$tempdir/wrapper-bz2") ? $tarball.".tmp" : $tarball; doit("xdelta", "patch", "$tempdir/delta", "$tempdir/recreatetarball", $out); if (-e "$tempdir/wrapper") { @@ -344,6 +349,15 @@ sub gentar { "gengz", "$tempdir/wrapper", $out); doit("mv", "-f", $out.".gz", $tarball); } + + if (-e "$tempdir/wrapper-bz2") { + doit("pristine-bz2", + ($verbose ? "-v" : "--no-verbose"), + ($debug ? "-d" : "--no-debug"), + ($keep ? "-k" : "--no-keep"), + "genbz2", "$tempdir/wrapper-bz2", $out); + doit("mv", "-f", $out.".bz2", $tarball); + } } sub genmanifest { @@ -376,7 +390,7 @@ sub gendelta { my @files=qw(delta manifest version type); - # Check to see if it's compressed. + # Check to see if it's gzip-compressed. open (IN, "<", $tarball) || error "Cannot read $tarball: $!\n"; my ($chars, $id1, $id2, $method); if (read(IN, $chars, 10) == 10 && @@ -393,7 +407,24 @@ sub gendelta { $tarball="$tempdir/origtarball"; } close IN; - + + # Check to see if it's bzip2-compressed. + open (IN, "<", $tarball) || error "Cannot read $tarball: $!\n"; + if (read(IN, $chars, 3) == 3 && + (($id1, $id2, $method) = unpack("CCC", $chars)) && + $id1 == BZIP2_ID1 && $id2 == BZIP2_ID2 && + $method == BZIP2_METHOD_HUFFMAN) { + doit("pristine-bz2", + ($verbose ? "-v" : "--no-verbose"), + ($debug ? "-d" : "--no-debug"), + ($keep ? "-k" : "--no-keep"), + "gendelta", $tarball, "$tempdir/wrapper-bz2"); + push @files, "wrapper-bz2"; + doit("bzcat $tarball > $tempdir/origtarball"); + $tarball="$tempdir/origtarball"; + } + close IN; + my $sourcedir="$tempdir/tmp"; doit("mkdir", $sourcedir); doit("tar", "xf", File::Spec->rel2abs($tarball), "-C", $sourcedir);