Browse Source

dpkg-source: Add new --no-overwrite-dir extraction option

Closes: #826334
Guillem Jover 10 years ago
parent
commit
ea7b527302

+ 1 - 0
debian/changelog

@@ -12,6 +12,7 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
   * Generate Testsuite-Triggers field from test dependencies in dpkg-source
   * Generate Testsuite-Triggers field from test dependencies in dpkg-source
     into .dsc files. Based on a patch by Martin Pitt <martin.pitt@ubuntu.com>.
     into .dsc files. Based on a patch by Martin Pitt <martin.pitt@ubuntu.com>.
     Closes: #779559
     Closes: #779559
+  * Add new dpkg-source --no-overwrite-dir extraction option. Closes: #826334
   * Perl modules:
   * Perl modules:
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Add new format_range() method and deprecate dpkg() and rfc822() methods
     - Add new format_range() method and deprecate dpkg() and rfc822() methods

+ 4 - 0
man/dpkg-source.1

@@ -258,6 +258,10 @@ Do not copy original tarballs near the extracted source package
 .BI \-\-no\-check
 .BI \-\-no\-check
 Do not check signatures and checksums before unpacking (since dpkg 1.14.17).
 Do not check signatures and checksums before unpacking (since dpkg 1.14.17).
 .TP
 .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
 .BI \-\-require\-valid\-signature
 Refuse to unpack the source package if it doesn't contain an OpenPGP
 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
 signature that can be verified (since dpkg 1.15.0) either with the user's

+ 2 - 1
scripts/Dpkg/Source/Package.pm

@@ -487,7 +487,8 @@ sub parse_cmdline_option {
 =item $p->extract($targetdir)
 =item $p->extract($targetdir)
 
 
 Extracts the source package in the target directory $targetdir. Beware
 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
 =cut
 
 

+ 5 - 1
scripts/Dpkg/Source/Package/V1.pm

@@ -192,7 +192,11 @@ sub do_extract {
         my $expectprefix = $newdirectory;
         my $expectprefix = $newdirectory;
         $expectprefix .= '.orig';
         $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) {
         if (-e $expectprefix) {
             rename($expectprefix, "$newdirectory.tmp-keep")
             rename($expectprefix, "$newdirectory.tmp-keep")
                 or syserr(g_("unable to rename '%s' to '%s'"), $expectprefix,
                 or syserr(g_("unable to rename '%s' to '%s'"), $expectprefix,

+ 5 - 1
scripts/Dpkg/Source/Package/V2.pm

@@ -208,7 +208,11 @@ sub do_extract {
             if $addonfile{$name} ne substr $addonsign{$name}, 0, -4;
             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
     # Extract main tarball
     info(g_('unpacking %s'), $tarfile);
     info(g_('unpacking %s'), $tarfile);

+ 5 - 1
scripts/Dpkg/Source/Package/V3/Bzr.pm

@@ -188,7 +188,11 @@ sub do_extract {
               "$basenamerev.bzr.tar.$comp_ext_regex", $tarfile);
               "$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
     # Extract main tarball
     info(g_('unpacking %s'), $tarfile);
     info(g_('unpacking %s'), $tarfile);

+ 5 - 1
scripts/Dpkg/Source/Package/V3/Git.pm

@@ -235,7 +235,11 @@ sub do_extract {
         error(g_('format v3.0 (git) expected %s'), "$basenamerev.git");
         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.
     # Extract git bundle.
     info(g_('cloning %s'), $bundle);
     info(g_('cloning %s'), $bundle);

+ 6 - 1
scripts/Dpkg/Source/Package/V3/Native.pm

@@ -58,7 +58,12 @@ sub do_extract {
 
 
     error(g_('no tarfile in Files field')) unless $tarfile;
     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);
     info(g_('unpacking %s'), $tarfile);
     my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
     my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
     $tar->extract($newdirectory);
     $tar->extract($newdirectory);

+ 4 - 0
scripts/dpkg-source.pl

@@ -67,6 +67,7 @@ my %options = (
     # Misc options
     # Misc options
     copy_orig_tarballs => 1,
     copy_orig_tarballs => 1,
     no_check => 0,
     no_check => 0,
+    no_overwrite_dir => 1,
     require_valid_signature => 0,
     require_valid_signature => 0,
     require_strong_checksums => 0,
     require_strong_checksums => 0,
 );
 );
@@ -190,6 +191,8 @@ while (@options) {
         $options{copy_orig_tarballs} = 0;
         $options{copy_orig_tarballs} = 0;
     } elsif (m/^--no-check$/) {
     } elsif (m/^--no-check$/) {
         $options{no_check} = 1;
         $options{no_check} = 1;
+    } elsif (m/^--no-overwrite-dir$/) {
+        $options{no_overwrite_dir} = 1;
     } elsif (m/^--require-valid-signature$/) {
     } elsif (m/^--require-valid-signature$/) {
         $options{require_valid_signature} = 1;
         $options{require_valid_signature} = 1;
     } elsif (m/^--require-strong-checksums$/) {
     } elsif (m/^--require-strong-checksums$/) {
@@ -644,6 +647,7 @@ sub usage {
 "Extract options:
 "Extract options:
   --no-copy                don't copy .orig tarballs
   --no-copy                don't copy .orig tarballs
   --no-check               don't check signature and checksums before unpacking
   --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-valid-signature abort if the package doesn't have a valid signature
   --require-strong-checksums
   --require-strong-checksums
                            abort if the package contains no strong checksums
                            abort if the package contains no strong checksums