[Reproducible-commits] [dpkg] 32/74: dpkg-source: Add new --no-overwrite-dir extraction option

Mattia Rizzolo mattia at debian.org
Sun Jul 3 22:22:54 UTC 2016


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

mattia pushed a commit to annotated tag 1.18.8
in repository dpkg.

commit ea7b5273024507d831578c7dd911a7293178b10c
Author: Guillem Jover <guillem at debian.org>
Date:   Mon Jun 6 03:18:47 2016 +0200

    dpkg-source: Add new --no-overwrite-dir extraction option
    
    Closes: #826334
---
 debian/changelog                         | 1 +
 man/dpkg-source.1                        | 4 ++++
 scripts/Dpkg/Source/Package.pm           | 3 ++-
 scripts/Dpkg/Source/Package/V1.pm        | 6 +++++-
 scripts/Dpkg/Source/Package/V2.pm        | 6 +++++-
 scripts/Dpkg/Source/Package/V3/Bzr.pm    | 6 +++++-
 scripts/Dpkg/Source/Package/V3/Git.pm    | 6 +++++-
 scripts/Dpkg/Source/Package/V3/Native.pm | 7 ++++++-
 scripts/dpkg-source.pl                   | 4 ++++
 9 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 63de0d3..bc05c0a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,7 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
   * Generate Testsuite-Triggers field from test dependencies in dpkg-source
     into .dsc files. Based on a patch by Martin Pitt <martin.pitt at ubuntu.com>.
     Closes: #779559
+  * Add new dpkg-source --no-overwrite-dir extraction option. Closes: #826334
   * Perl modules:
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Add new format_range() method and deprecate dpkg() and rfc822() methods
diff --git a/man/dpkg-source.1 b/man/dpkg-source.1
index 8e3b932..d916a91 100644
--- a/man/dpkg-source.1
+++ b/man/dpkg-source.1
@@ -258,6 +258,10 @@ Do not copy original tarballs near the extracted source package
 .BI \-\-no\-check
 Do not check signatures and checksums before unpacking (since dpkg 1.14.17).
 .TP
+.B \-\-no\-overwrite\-dir
+Do not overwrite the extraction directory if it already exists
+(since dpkg 1.18.8).
+.TP
 .BI \-\-require\-valid\-signature
 Refuse to unpack the source package if it doesn't contain an OpenPGP
 signature that can be verified (since dpkg 1.15.0) either with the user's
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 969366b..fe4c20c 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -487,7 +487,8 @@ sub parse_cmdline_option {
 =item $p->extract($targetdir)
 
 Extracts the source package in the target directory $targetdir. Beware
-that if $targetdir already exists, it will be erased.
+that if $targetdir already exists, it will be erased (as long as the
+no_overwrite_dir option is set).
 
 =cut
 
diff --git a/scripts/Dpkg/Source/Package/V1.pm b/scripts/Dpkg/Source/Package/V1.pm
index 8d1efa9..85242bf 100644
--- a/scripts/Dpkg/Source/Package/V1.pm
+++ b/scripts/Dpkg/Source/Package/V1.pm
@@ -192,7 +192,11 @@ sub do_extract {
         my $expectprefix = $newdirectory;
         $expectprefix .= '.orig';
 
-        erasedir($newdirectory);
+        if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
+            error(g_('unpack target exists: %s'), $newdirectory);
+        } else {
+            erasedir($newdirectory);
+        }
         if (-e $expectprefix) {
             rename($expectprefix, "$newdirectory.tmp-keep")
                 or syserr(g_("unable to rename '%s' to '%s'"), $expectprefix,
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index 6268b55..19970e5 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -208,7 +208,11 @@ sub do_extract {
             if $addonfile{$name} ne substr $addonsign{$name}, 0, -4;
     }
 
-    erasedir($newdirectory);
+    if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
+        error(g_('unpack target exists: %s'), $newdirectory);
+    } else {
+        erasedir($newdirectory);
+    }
 
     # Extract main tarball
     info(g_('unpacking %s'), $tarfile);
diff --git a/scripts/Dpkg/Source/Package/V3/Bzr.pm b/scripts/Dpkg/Source/Package/V3/Bzr.pm
index 6cf8fae..058c96b 100644
--- a/scripts/Dpkg/Source/Package/V3/Bzr.pm
+++ b/scripts/Dpkg/Source/Package/V3/Bzr.pm
@@ -188,7 +188,11 @@ sub do_extract {
               "$basenamerev.bzr.tar.$comp_ext_regex", $tarfile);
     }
 
-    erasedir($newdirectory);
+    if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
+        error(g_('unpack target exists: %s'), $newdirectory);
+    } else {
+        erasedir($newdirectory);
+    }
 
     # Extract main tarball
     info(g_('unpacking %s'), $tarfile);
diff --git a/scripts/Dpkg/Source/Package/V3/Git.pm b/scripts/Dpkg/Source/Package/V3/Git.pm
index 115b3c7..c9a056b 100644
--- a/scripts/Dpkg/Source/Package/V3/Git.pm
+++ b/scripts/Dpkg/Source/Package/V3/Git.pm
@@ -235,7 +235,11 @@ sub do_extract {
         error(g_('format v3.0 (git) expected %s'), "$basenamerev.git");
     }
 
-    erasedir($newdirectory);
+    if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
+        error(g_('unpack target exists: %s'), $newdirectory);
+    } else {
+        erasedir($newdirectory);
+    }
 
     # Extract git bundle.
     info(g_('cloning %s'), $bundle);
diff --git a/scripts/Dpkg/Source/Package/V3/Native.pm b/scripts/Dpkg/Source/Package/V3/Native.pm
index ea38c27..b53a30f 100644
--- a/scripts/Dpkg/Source/Package/V3/Native.pm
+++ b/scripts/Dpkg/Source/Package/V3/Native.pm
@@ -58,7 +58,12 @@ sub do_extract {
 
     error(g_('no tarfile in Files field')) unless $tarfile;
 
-    erasedir($newdirectory);
+    if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
+        error(g_('unpack target exists: %s'), $newdirectory);
+    } else {
+        erasedir($newdirectory);
+    }
+
     info(g_('unpacking %s'), $tarfile);
     my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
     $tar->extract($newdirectory);
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 50885bb..40a70fd 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -67,6 +67,7 @@ my %options = (
     # Misc options
     copy_orig_tarballs => 1,
     no_check => 0,
+    no_overwrite_dir => 1,
     require_valid_signature => 0,
     require_strong_checksums => 0,
 );
@@ -190,6 +191,8 @@ while (@options) {
         $options{copy_orig_tarballs} = 0;
     } elsif (m/^--no-check$/) {
         $options{no_check} = 1;
+    } elsif (m/^--no-overwrite-dir$/) {
+        $options{no_overwrite_dir} = 1;
     } elsif (m/^--require-valid-signature$/) {
         $options{require_valid_signature} = 1;
     } elsif (m/^--require-strong-checksums$/) {
@@ -644,6 +647,7 @@ sub usage {
 "Extract options:
   --no-copy                don't copy .orig tarballs
   --no-check               don't check signature and checksums before unpacking
+  --no-overwrite-dir       do not overwrite directory on extraction
   --require-valid-signature abort if the package doesn't have a valid signature
   --require-strong-checksums
                            abort if the package contains no strong checksums

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list