Quellcode durchsuchen

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

Closes: #826334
Guillem Jover vor 10 Jahren
Ursprung
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
     into .dsc files. Based on a patch by Martin Pitt <martin.pitt@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

+ 4 - 0
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

+ 2 - 1
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
 

+ 5 - 1
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,

+ 5 - 1
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);

+ 5 - 1
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);

+ 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");
     }
 
-    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);

+ 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;
 
-    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);

+ 4 - 0
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