Hello again!

Sorry for all the "spam" but I think the patch enclosed in this email is
the most succinct.

Best regards

-- 
Muharem Hrnjadovic <[email protected]>
Public key id   : B2BBFCFC
Key fingerprint : A5A3 CC67 2B87 D641 103F  5602 219F 6B60 B2BB FCFC
=== modified file 'pristine-tar'
--- pristine-tar	2009-09-07 06:22:43 +0000
+++ pristine-tar	2009-09-07 11:27:33 +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,49 @@
 	close OUT;
 }
 
+sub trimpath {
+    # Remove the first path segment and trailing slashes (if any) as well as
+    # leading/trailing whitespace.
+    my $path=shift;
+    
+    chomp $path;
+    $path =~ s,[^/]+/,,;
+    $path =~ s,/*$,,;
+    $path =~ s/^\s*//;
+    $path =~ s/\s*$//; 
+
+    return $path;
+}
+
+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 { $_ = trimpath($File::Find::name); push(@files_in_tree,  $_) if $_ ne "" }, qw(.);
+
+	open(IN, "<", $manifest) || die "$!";
+	while (<IN>) {
+        $_ = trimpath($_);
+        push(@manifest_entries, $_) if $_ ne "";
+	}
+	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("Files missing in source tree: ", join(", ", @missing_in_tree));
+    return @missing_in_tree;
+}
+
 sub gendelta {
 	my $tarball=shift;
 	my $delta=shift;
@@ -399,6 +443,20 @@
 
 	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");
+
+    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 +507,6 @@
 		$tarball="$tempdir/origtarball";
 	}
 
-	genmanifest($tarball, "$tempdir/manifest");
 	my $recreatetarball;
 	if (! exists $opts{recreatetarball}) {
 		my $sourcedir="$tempdir/tmp";

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to