瀏覽代碼

dpkg-source: be less strict on filenames accepted in patches

* scripts/Dpkg/Source/Patch.pm (analyze): Be less strict in
filenames accepted on ---/+++ lines. Don't blow up on absolute
filenames if the other one is fine. Make sure to use the one that
is relative and that corresponds to a real file when possible.
Raphael Hertzog 18 年之前
父節點
當前提交
0c039711ca
共有 2 個文件被更改,包括 32 次插入17 次删除
  1. 7 0
      ChangeLog
  2. 25 17
      scripts/Dpkg/Source/Patch.pm

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-06-08  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/Dpkg/Source/Patch.pm (analyze): Be less strict in
+	filenames accepted on ---/+++ lines. Don't blow up on absolute
+	filenames if the other one is fine. Make sure to use the one that
+	is relative and that corresponds to a real file when possible.
+
 2008-06-08  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/Dpkg/Source/Package/V3/quilt.pm: Use absolute path names

+ 25 - 17
scripts/Dpkg/Source/Patch.pm

@@ -305,6 +305,7 @@ sub analyze {
 
   HUNK:
     while (defined($_) || not eof($diff_handle)) {
+	my ($fn, $fn2);
 	# skip comments leading up to patch (if any)
 	until (/^--- /) {
 	    last HUNK if not defined($_ = getline($diff_handle));
@@ -315,13 +316,12 @@ sub analyze {
 	    error(_g("expected ^--- in line %d of diff `%s'"), $., $diff);
 	}
         $_ = strip_ts($_);
-	unless ($_ eq '/dev/null' or s{^(\./)?[^/]+/}{$destdir/}) {
-	    error(_g("diff `%s' patches file with no subdirectory"), $diff);
-	}
+        if ($_ eq '/dev/null' or s{^(\./)?[^/]+/}{$destdir/}) {
+            $fn = $_;
+        }
 	if (/\.dpkg-orig$/) {
 	    error(_g("diff `%s' patches file with name ending .dpkg-orig"), $diff);
 	}
-	my $fn = $_;
 
 	unless (defined($_ = getline($diff_handle))) {
 	    error(_g("diff `%s' finishes in middle of ---/+++ (line %d)"), $diff, $.);
@@ -330,20 +330,28 @@ sub analyze {
 	    error(_g("line after --- isn't as expected in diff `%s' (line %d)"), $diff, $.);
 	}
         $_ = strip_ts($_);
-	unless (($_ eq '/dev/null') or s!^(\./)?[^/]+/!!) {
-	    error(_g("line after --- isn't as expected in diff `%s' (line %d)"), $diff, $.);
-	}
+        if ($_ eq '/dev/null' or s{^(\./)?[^/]+/}{$destdir/}) {
+            $fn2 = $_;
+        } else {
+            unless (defined $fn) {
+                error(_g("none of the filenames in ---/+++ are relative in diff `%s' (line %d)"),
+                      $diff, $.);
+            }
+        }
 
-	if ($fn eq '/dev/null') {
-	    error(_g("original and modified files are /dev/null in diff `%s' (line %d)"),
-		  $diff, $.) if $_ eq '/dev/null';
-	    $fn = "$destdir/$_";
-	} elsif ($_ ne '/dev/null') {
-            $fn = "$destdir/$_" if ((not -e $fn) and -e "$destdir/$_");
-	    unless ($_ eq substr($fn, length($destdir) + 1)) {
-	        error(_g("line after --- isn't as expected in diff `%s' (line %d)"), $diff, $.);
-	    }
-	}
+        if (defined($fn) and $fn eq '/dev/null') {
+            error(_g("original and modified files are /dev/null in diff `%s' (line %d)"),
+                  $diff, $.) if (defined($fn2) and $fn2 eq '/dev/null');
+            $fn = $fn2;
+        } elsif (defined($fn2) and $fn2 ne '/dev/null') {
+            $fn = $fn2 unless defined $fn;
+            $fn = $fn2 if ((not -e $fn) and -e $fn2);
+        } elsif (defined($fn2) and $fn2 eq '/dev/null') {
+            error(_g("file removal without proper filename in diff `%s' (line %d)"),
+                  $diff, $. - 1) unless defined $fn;
+            warning(_g("diff %s removes a non-existing file %s (line %d)"),
+                    $diff, $fn, $.) unless -e $fn;
+        }
 
 	my $dirname = $fn;
 	if ($dirname =~ s{/[^/]+$}{} && not -d $dirname) {