Package: pristine-tar
Version: 1.00
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


pristine-tar's "gendelta" command does not check whether all paths in
the manifest are also present in the local/unpacked source tree.

It thus generates a "broken" delta when something is missing from the
unpacked source tree (since not all the files required for generating
a pristine tar *later* are actually available).

It should abort with an error instead.

The error can be reproduced easily:

{{{
$ apt-get source apg
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Need to get 90.2kB of source archives.
Get: 1 http://us.archive.ubuntu.com karmic/universe apg 2.2.3.dfsg.1-2 (dsc) 
[620B]
Get: 2 http://us.archive.ubuntu.com karmic/universe apg 2.2.3.dfsg.1-2 (tar) 
[83.6kB]
Get: 3 http://us.archive.ubuntu.com karmic/universe apg 2.2.3.dfsg.1-2 (diff) 
[5993B]
Fetched 90.2kB in 0s (208kB/s)
dpkg-source: info: extracting apg in apg-2.2.3.dfsg.1
dpkg-source: info: unpacking apg_2.2.3.dfsg.1.orig.tar.gz
dpkg-source: info: applying apg_2.2.3.dfsg.1-2.diff.gz
$ cd apg-2.2.3.dfsg.1/
$ rm README.CYGWIN
$ pristine-tar gendelta ../apg_2.2.3.dfsg.1.orig.tar.gz ../brokendelta
$ echo $?
0
$ rm ../apg_2.2.3.dfsg.1.orig.tar.gz
$ pristine-tar gentar ../brokendelta ../apg_2.2.3.dfsg.1.orig.tar.gz
tar: apg-2.2.3.dfsg.1/README.CYGWIN: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
pristine-tar: command failed: tar cf 
/tmp/pristine-tar.lLB0MOTtSg/recreatetarball --owner 0 --group 0 
--numeric-owner -C /tmp/pristine-tar.lLB0MOTtSg/workdir --no-recursion --mode 
0644 --files-from /tmp/pristine-tar.lLB0MOTtSg/manifest
}}}


*** proposed.diff
=== modified file 'pristine-tar'
- --- pristine-tar      2009-09-07 06:22:43 +0000
+++ pristine-tar        2009-09-07 08:46:06 +0000
@@ -122,9 +122,10 @@
 
 use warnings;
 use strict;
+use File::Basename;
+use File::Find;
+use File::Path;
 use File::Temp;
- -use File::Path;
- -use File::Basename;
 use Getopt::Long;
 use Cwd qw{getcwd abs_path};
 
@@ -392,6 +393,41 @@
        close OUT;
 }
 
+sub checkmanifest {
+    # Find all paths that are listed in the manifest but do *not* exist in
+    # the source tree.
+       my $manifest=shift;
+
+    my @manifest_entries = ();
+    my @files_in_tree = ();
+
+    # The local function will strip off the './' prefix of all paths.
+    find sub { ($_ = $File::Find::name) =~ s![^/]+/!!; push(@files_in_tree,  
$_) }, qw(.);
+
+       open(IN, "<", $manifest) || die "$!";
+       while (<IN>) {
+               chomp;
+        # Strip off leading path segment so we can compare these paths with
+        # the ones found in the local source tree.
+        s,[^/]+/,,;
+        # Strip off trailing slashes (if any) so we can compare these paths
+        # with the ones found in the local source tree.
+        s,/*$,,;
+        push(@manifest_entries, $_);
+       }
+       close IN;
+
+    # Compare the paths found in the manifest with the ones in the local
+    # source tree.
+    my %seen;
+    @seen {...@manifest_entries} = ();
+    delete @seen {...@files_in_tree};
+    my @missing_in_tree = sort(keys %seen);
+
+    debug("$#missing_in_tree files missing in source tree: @missing_in_tree");
+    return @missing_in_tree;
+}
+
 sub gendelta {
        my $tarball=shift;
        my $delta=shift;
@@ -399,6 +435,21 @@
 
        my $tempdir=tempdir();
        
+    genmanifest($tarball, "$tempdir/manifest");
+
+    # Check whether all paths in the manifest are also present in the source
+    # tree.
+    # If not, we'll be generating a "broken" delta since not all the paths
+    # required for generating a pristine tar later are actually available.
+    my @missing_in_tree = checkmanifest("$tempdir/manifest");
+    debug("$#missing_in_tree files missing in source tree: @missing_in_tree");
+
+    if ($#missing_in_tree > 0) {
+        # Abort here since we don't have all the files required for generating
+        # a pristine tar in the source tree.
+        error("Files missing in source tree: @missing_in_tree");
+    }
+
        my $stdout=0;
        if ($delta eq "-") {
                $stdout=1;
@@ -449,7 +500,6 @@
                $tarball="$tempdir/origtarball";
        }
 
- -     genmanifest($tarball, "$tempdir/manifest");
        my $recreatetarball;
        if (! exists $opts{recreatetarball}) {
                my $sourcedir="$tempdir/tmp";



- -- System Information:
Debian Release: squeeze/sid
  APT prefers karmic-security
  APT policy: (500, 'karmic-security'), (500, 'karmic')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.31-9-generic (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iQIcBAEBCAAGBQJKpNggAAoJECGfa2Cyu/z82sUP/3YB9Rto71r3WPgDYuvYn4LW
mKZg0tVYEjpnlnzD4/aM1GXctxp+llUZIL6SQmzv5mG8aF2iUQ528mhFwBFMat7p
L7abh8f8Y68F39PD9W4YkG5WZ9fJkEKaHkiXmaMWsg3BSNisnga7VxIYammPOhZU
Big5pxkR22S1FlZB384NPA7h+uuWBXJI+e7OThuKiKDxAo8dbsn4YnxC6tE1baVm
vQW2GBIcmvrAuBq1MPvkw0hZo2Cbuxvt358pZYiXoUO5qzN0XWx+lTbxi9ZR3ksY
C3SlO/fpHx+hL2TkBnAjVcKPnIFN2T6ug4YOpO3u3/wNPZJXdLGbi18/vo+uf7om
Svd8czcFc8VYkC3LlnzDww9FG4soJU9r9ywR8CzprkbXuEKJE+OScAviQVGhp8+A
/0UIBPqQGbHs7dT9fTsPcQnq9AAu+i5bogSTWzI/KgtL1keEa2KE0lfOa5F7KkoK
rApUWrLGsihAH0vvT4bj+Pd193bMkiilwqTgolKe5jx/8oF2bt579JHqINo8Ro7s
adXOpsElN1AI/YEbX/Awz3w9CK/kp/SxH6kTtvSYjymcx49b6LtDMfXouPyW/BAe
CEOFdCppJTkWGIKmb5/BtE6IK7QkTCaOLs9xlWpsLfmQJF/Jaxam01tEElEZ/P67
rCwACMi+M42qL4QwyiRN
=WGoj
-----END PGP SIGNATURE-----



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to