summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2018-06-08 03:22:36 +0200
committerGuillem Jover <guillem@debian.org>2018-08-01 05:27:49 +0200
commit9ab6c592c04c06952019e5c9bba57b2b54aa3fae (patch)
tree38415d92599122c3d9eecd241a90afb97a733d6a
parent738c8d5d545e164c3e7450751960618443bf7431 (diff)
downloaddpkg-9ab6c592c04c06952019e5c9bba57b2b54aa3fae.tar.gz
Dpkg::Source: Do not change patch permissions if not necessary
To be able to build a source tree, a user needs write permisions on it, but not necessarily ownership of those files. We check the existing file permissions and avoid changing them if not necessary, which helps in the case where the user does not have ownership of those files, and they were already present. Closes: #898010 Naming-by: Julian Andres Klode <jak@debian.org>
-rw-r--r--debian/changelog2
-rw-r--r--scripts/Dpkg/Source/Functions.pm13
-rw-r--r--scripts/Dpkg/Source/Package/V2.pm4
-rw-r--r--scripts/Dpkg/Source/Package/V3/Quilt.pm4
-rw-r--r--scripts/Dpkg/Source/Quilt.pm4
5 files changed, 21 insertions, 6 deletions
diff --git a/debian/changelog b/debian/changelog
index d0c53872d..28568a5c4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -131,6 +131,8 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
modules.
- Dpkg::Gettext: Fix fallback textdomain() to honor its expected interface.
- Dpkg::Deps: Split subpackages into their own separate modules.
+ - Dpkg::Source: Do not change patch permissions if not necessary.
+ Closes: #898010
* Documentation:
- Update gettext minimal version in README.
- Add a missing dot on the dpkg-buildflags(1) «lfs» feature paragraph.
diff --git a/scripts/Dpkg/Source/Functions.pm b/scripts/Dpkg/Source/Functions.pm
index 0a940463e..dcb957e13 100644
--- a/scripts/Dpkg/Source/Functions.pm
+++ b/scripts/Dpkg/Source/Functions.pm
@@ -22,6 +22,7 @@ our $VERSION = '0.01';
our @EXPORT_OK = qw(
erasedir
fixperms
+ chmod_if_needed
fs_time
is_binary
);
@@ -70,6 +71,18 @@ sub fixperms {
subprocerr("chmod -R -- $modes_set $dir") if $?;
}
+# Only change the pathname permissions if they differ from the desired.
+#
+# To be able to build a source tree, a user needs write permisions on it,
+# but not necessarily ownership of those files.
+sub chmod_if_needed {
+ my ($newperms, $pathname) = @_;
+ my $oldperms = (stat $pathname)[2] & 07777;
+
+ return 1 if $oldperms == $newperms;
+ return chmod $newperms, $pathname;
+}
+
# Touch the file and read the resulting mtime.
#
# If the file doesn't exist, create it, read the mtime and unlink it.
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index 13e5d7456..2c8529bc1 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -38,7 +38,7 @@ use Dpkg::Compression;
use Dpkg::Source::Archive;
use Dpkg::Source::Patch;
use Dpkg::Exit qw(push_exit_handler pop_exit_handler);
-use Dpkg::Source::Functions qw(erasedir is_binary fs_time);
+use Dpkg::Source::Functions qw(erasedir chmod_if_needed is_binary fs_time);
use Dpkg::Vendor qw(run_vendor_hook);
use Dpkg::Control;
use Dpkg::Changelog::Parse;
@@ -673,7 +673,7 @@ sub register_patch {
if (-s $patch_file) {
copy($patch_file, $patch)
or syserr(g_('failed to copy %s to %s'), $patch_file, $patch);
- chmod(0666 & ~ umask(), $patch)
+ chmod_if_needed(0666 & ~ umask(), $patch)
or syserr(g_("unable to change permission of '%s'"), $patch);
my $applied = File::Spec->catfile($dir, 'debian', 'patches', '.dpkg-source-applied');
open(my $applied_fh, '>>', $applied)
diff --git a/scripts/Dpkg/Source/Package/V3/Quilt.pm b/scripts/Dpkg/Source/Package/V3/Quilt.pm
index 9718ffa2d..7c6137c28 100644
--- a/scripts/Dpkg/Source/Package/V3/Quilt.pm
+++ b/scripts/Dpkg/Source/Package/V3/Quilt.pm
@@ -28,7 +28,7 @@ use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Version;
use Dpkg::Source::Patch;
-use Dpkg::Source::Functions qw(erasedir fs_time);
+use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time);
use Dpkg::Source::Quilt;
use Dpkg::Exit;
@@ -249,7 +249,7 @@ sub register_patch {
if (-s $tmpdiff) {
copy($tmpdiff, $patch)
or syserr(g_('failed to copy %s to %s'), $tmpdiff, $patch);
- chmod(0666 & ~ umask(), $patch)
+ chmod_if_needed(0666 & ~ umask(), $patch)
or syserr(g_("unable to change permission of '%s'"), $patch);
} elsif (-e $patch) {
unlink($patch) or syserr(g_('cannot remove %s'), $patch);
diff --git a/scripts/Dpkg/Source/Quilt.pm b/scripts/Dpkg/Source/Quilt.pm
index 55b3fbaf8..78a4fdf9a 100644
--- a/scripts/Dpkg/Source/Quilt.pm
+++ b/scripts/Dpkg/Source/Quilt.pm
@@ -30,7 +30,7 @@ use File::Basename;
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Source::Patch;
-use Dpkg::Source::Functions qw(erasedir fs_time);
+use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time);
use Dpkg::Vendor qw(get_current_vendor);
sub new {
@@ -374,7 +374,7 @@ sub restore_quilt_backup_files {
unless (link($_, $target)) {
copy($_, $target)
or syserr(g_('failed to copy %s to %s'), $_, $target);
- chmod((stat(_))[2], $target)
+ chmod_if_needed((stat _)[2], $target)
or syserr(g_("unable to change permission of '%s'"), $target);
}
} else {