[devscripts] 01/07: mk-origtargz: Only tell tar to delete a file once

James McCoy jamessan at debian.org
Mon Feb 16 04:09:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch master
in repository devscripts.

commit 7d8f5b323502ef9a09821c8c5a5f0a3690ee5f7a
Author: James McCoy <jamessan at debian.org>
Date:   Fri Feb 13 20:38:13 2015 -0500

    mk-origtargz: Only tell tar to delete a file once
    
    If Files-Excluded has multiple patterns which match the same file, we
    should only use the filename once.  This avoids errors when calling tar,
    but may cause new diagnostics to be emitted about unused patterns.
    
    Closes: #776318
    Signed-off-by: James McCoy <jamessan at debian.org>
---
 debian/changelog        |  3 +++
 scripts/mk-origtargz.pl | 15 ++++++++++++---
 test/test_mk-origtargz  | 24 ++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 547281c..2c73634 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,9 @@ devscripts (2.15.1+exp1) UNRELEASED; urgency=medium
     + Remove 404ing myon and debug URLs
     + Use https://api.ftp-master.debian.org/madison for debian and new URLs.
       This also fixes support for the -b option.  (Closes: #775084)
+  * mk-origtargz: Avoid adding the same file to the "to be deleted" list
+    multiple times.  This may also cause patterns to be declared as unused if
+    a file is matched by multiple patterns.  (Closes: #776318)
 
   [ Johannes Schauer ]
   * chdist: Also set Apt::Architectures to prevent foreign architectures from
diff --git a/scripts/mk-origtargz.pl b/scripts/mk-origtargz.pl
index 4a6d6e0..6197537 100755
--- a/scripts/mk-origtargz.pl
+++ b/scripts/mk-origtargz.pl
@@ -3,6 +3,7 @@
 # mk-origtargz: Rename upstream tarball, optionally changing the compression
 # and removing unwanted files.
 # Copyright (C) 2014 Joachim Breitner <nomeata at debian.org>
+# Copyright (C) 2015 James McCoy <jamessan at debian.org>
 #
 # It contains code formerly found in uscan.
 # Copyright (C) 2002-2006, Julian Gilbey
@@ -78,7 +79,11 @@ B<Files-Excluded>.
 
 =item B<--copyright-file> I<filename>
 
-Remove files matching the patterns found in I<filename>, which should have the format of a Debian F<copyright> file (B<Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/> to be precise). Errors parsing that file are silently ignored, exactly as it is the case with F<debian/copyright>.
+Remove files matching the patterns found in I<filename>, which should have the format of a Debian F<copyright> file (B<Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/> to be precise). Errors parsing that file are silently ignored, exactly as is the case with F<debian/copyright>.
+
+Unmatched patterns will emit a warning so the user can verify whether it is
+correct.  If there are multiple patterns which match a file, only the last one
+will count as being matched.
 
 Both the B<--exclude-file> and B<--copyright-file> options amend the list of
 patterns found in F<debian/copyright>. If you do not want to read that file,
@@ -422,15 +427,19 @@ if (@exclude_globs) {
     # find out what to delete
     my @exclude_info = map { { glob => $_, used => 0, regex => glob_to_regex($_) } } @exclude_globs;
     for my $filename (@files) {
+	my $last_match;
 	for my $info (@exclude_info) {
 	    if ($filename =~ m@^(?:[^/]*/)?        # Possible leading directory, ignore it
 				(?:$info->{regex}) # User pattern
 				(?:/.*)?$          # Possible trailing / for a directory
 			      @x) {
-		push @to_delete, $filename;
-		$info->{used} = 1;
+		push @to_delete, $filename if !$last_match;
+		$last_match = $info;
 	    }
 	}
+	if ($last_match) {
+	    $last_match->{used} = 1;
+	}
     }
 
     for my $info (@exclude_info) {
diff --git a/test/test_mk-origtargz b/test/test_mk-origtargz
index ad5a729..615d31d 100755
--- a/test/test_mk-origtargz
+++ b/test/test_mk-origtargz
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 # Copyright 2014, Rafael Laboissiere <rafael at laboissiere.net>
+# Copyright 2015, James McCoy <jamessan at debian.org>
 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by the
@@ -146,6 +147,17 @@ Files-Excluded: exclude-this*
 END
 }
 
+makeDuplicatePatternCopyright() {
+	cat <<'END' > $TMPDIR/foo/debian/copyright
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Files-Excluded: exclude-this*
+ .exclude-this*
+ exclude-dir1
+ exclude-dir*
+ ;?echo?strange-file;?#
+END
+}
+
 expected_stderr_after_removal="WARNING: Files-Excluded pattern (exclude-dir2/) should not have a trailing /"
 
 expected_files_after_removal=$(sort <<END
@@ -540,4 +552,16 @@ testUnmatchedExclusion() {
 	assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.gz | sort)"
 }
 
+testDuplicatePattern() {
+	makeTarBall gz
+	makeDebianDir
+	makeDuplicatePatternCopyright
+	run_mk_origtargz foo "No files matched excluded pattern: exclude-dir1" \
+		"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.gz, deleting 19 files from it." \
+		 ../foo-0.1.tar.gz
+	assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
+	assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
+	assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.gz | sort)"
+}
+
 . shunit2

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list