[debhelper-devel] [debhelper] 01/01: reset_perm_and_owner: Use perl functions instead of fork+exec

Niels Thykier nthykier at moszumanska.debian.org
Wed Jul 12 19:55:47 UTC 2017


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

nthykier pushed a commit to branch master
in repository debhelper.

commit 378dfa200576c1823241f47fff88224a051a0a68
Author: Niels Thykier <niels at thykier.net>
Date:   Wed Jul 12 19:35:11 2017 +0000

    reset_perm_and_owner: Use perl functions instead of fork+exec
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 20 ++++++++++++++++++--
 debian/changelog           |  2 ++
 dh_bugfiles                |  4 ++--
 dh_fixperms                |  4 ++--
 dh_gencontrol              |  4 ++--
 dh_installchangelogs       |  2 +-
 dh_installdeb              |  2 +-
 dh_makeshlibs              |  2 +-
 dh_md5sums                 |  4 ++--
 dh_strip                   |  2 +-
 10 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 56ebeaf..744c9f1 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -430,8 +430,24 @@ sub rename_path {
 
 sub reset_perm_and_owner {
 	my ($mode, @paths) = @_;
-	doit('chmod', $mode, '--', @paths);
-	doit('chown', '0:0', '--', @paths);
+	my $_mode;
+	# Dark goat blood to tell 0755 from "0755"
+	if (length( do { no warnings "numeric"; $mode & "" } ) ) {
+		# 0755, leave it alone.
+		$_mode = $mode;
+	} else {
+		# "0755" -> convert to 0755
+		$_mode = oct($mode);
+	}
+	if ($dh{VERBOSE}) {
+		verbose_print(sprintf('chmod %#o -- %s', $_mode, escape_shell(@paths)));
+		verbose_print(sprintf('chown 0:0 -- %s', escape_shell(@paths)));
+	}
+	return if $dh{NO_ACT};
+	for my $path (@paths) {
+		chmod($_mode, $path) or error(sprintf('chmod(%#o, %s): %s', $mode, $path, $!));
+		chown(0, 0, $path) or error("chown(0, 0, $path): $!");
+	}
 }
 
 # Run a command that may have a huge number of arguments, like xargs does.
diff --git a/debian/changelog b/debian/changelog
index 4480700..f6525fd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,8 @@ debhelper (10.6.4) UNRELEASED; urgency=medium
     where dh_installman would fail to remove the compressed manpage.
     With hardlinks involved, this could make dh_compress fail later.
     (Closes: #867846)
+  * Dh_lib.pm: Rewrite reset_perm_and_owner to it does chmod + chown
+    using perl built-ins rather than forking+exec.
 
  -- Niels Thykier <niels at thykier.net>  Sun, 09 Jul 2017 12:30:20 +0000
 
diff --git a/dh_bugfiles b/dh_bugfiles
index 62b9ac9..552c122 100755
--- a/dh_bugfiles
+++ b/dh_bugfiles
@@ -123,10 +123,10 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	
 	# Ensure that the bug script is executable
 	if (-f $dir) {
-		reset_perm_and_owner('0755', $dir);
+		reset_perm_and_owner(0755, $dir);
 	}
 	elsif (-f "$dir/script") {
-		reset_perm_and_owner('0755', "$dir/script");
+		reset_perm_and_owner(0755, "$dir/script");
 	}
 }
 
diff --git a/dh_fixperms b/dh_fixperms
index 6f7017a..923d174 100755
--- a/dh_fixperms
+++ b/dh_fixperms
@@ -133,10 +133,10 @@ on_pkgs_in_parallel {
 						 "! -name 'script' ${find_exclude_options} -print0",
 						 "2>/dev/null | xargs -0r chmod 644");
 			if ( -f "$tmp/usr/share/bug/$package/script" ) {
-				reset_perm_and_owner('0755', "$tmp/usr/share/bug/$package/script");
+				reset_perm_and_owner(0755, "$tmp/usr/share/bug/$package/script");
 			}
 		} elsif ( -f "$tmp/usr/share/bug/$package" ) {
-			reset_perm_and_owner('0755', "$tmp/usr/share/bug/$package");
+			reset_perm_and_owner(0755, "$tmp/usr/share/bug/$package");
 		}
 
 		# Files in $tmp/etc/sudoers.d/ must be mode 0440.
diff --git a/dh_gencontrol b/dh_gencontrol
index aae4b22..790f733 100755
--- a/dh_gencontrol
+++ b/dh_gencontrol
@@ -128,7 +128,7 @@ on_pkgs_in_parallel {
 			doit("dpkg-gencontrol", "-p${package}", "-l$changelog", "-T$substvars",
 				"-P${dbgsym_tmp}",@{$dh{U_PARAMS}}, @dbgsym_options);
 
-			reset_perm_and_owner('0644', "${dbgsym_tmp}/DEBIAN/control");
+			reset_perm_and_owner(0644, "${dbgsym_tmp}/DEBIAN/control");
 		} elsif ($build_ids) {
 			# Only include the build-id if there is no dbgsym package (if
 			# there is a dbgsym package, the build-ids into the control
@@ -147,7 +147,7 @@ on_pkgs_in_parallel {
 
 		# This chmod is only necessary if the user sets the umask to
 		# something odd.
-		reset_perm_and_owner('0644', "${tmp}/DEBIAN/control");
+		reset_perm_and_owner(0644, "${tmp}/DEBIAN/control");
 	}
 };
 
diff --git a/dh_installchangelogs b/dh_installchangelogs
index 18b9bc0..3c377a5 100755
--- a/dh_installchangelogs
+++ b/dh_installchangelogs
@@ -227,7 +227,7 @@ on_pkgs_in_parallel {
 				$link_to='changelog.html';
 				if (! defined $upstream_text) {
 					complex_doit("echo 'See changelog.html.gz' > $base/changelog");
-					reset_perm_and_owner('0644',"$base/changelog");
+					reset_perm_and_owner(0644,"$base/changelog");
 				}
 			}
 			if ($dh{K_FLAG}) {
diff --git a/dh_installdeb b/dh_installdeb
index 60b1fbb..0472e54 100755
--- a/dh_installdeb
+++ b/dh_installdeb
@@ -184,7 +184,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			rm_files("$tmp/DEBIAN/conffiles");
 		}
 		else {
-			reset_perm_and_owner('0644', "$tmp/DEBIAN/conffiles");
+			reset_perm_and_owner(0644, "$tmp/DEBIAN/conffiles");
 		}
 	}
 }
diff --git a/dh_makeshlibs b/dh_makeshlibs
index 7f7bf59..e44930f 100755
--- a/dh_makeshlibs
+++ b/dh_makeshlibs
@@ -241,7 +241,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	}
 
 	if (-e "$tmp/DEBIAN/shlibs") {
-		reset_perm_and_owner('0644', "$tmp/DEBIAN/shlibs");
+		reset_perm_and_owner(0644, "$tmp/DEBIAN/shlibs");
 	}
 
 	# dpkg-gensymbols files
diff --git a/dh_md5sums b/dh_md5sums
index b3a3a74..c94f8f2 100755
--- a/dh_md5sums
+++ b/dh_md5sums
@@ -87,7 +87,7 @@ on_pkgs_in_parallel {
 			rm_files("$tmp/DEBIAN/md5sums");
 		}
 		else {
-			reset_perm_and_owner('0644', "$tmp/DEBIAN/md5sums");
+			reset_perm_and_owner(0644, "$tmp/DEBIAN/md5sums");
 		}
 		if ( -d $dbgsym_tmp) {
 			install_dir("${dbgsym_tmp}/DEBIAN");
@@ -100,7 +100,7 @@ on_pkgs_in_parallel {
 				rm_files("${dbgsym_tmp}/DEBIAN/md5sums");
 			}
 			else {
-				reset_perm_and_owner('0644', "${dbgsym_tmp}/DEBIAN/md5sums");
+				reset_perm_and_owner(0644, "${dbgsym_tmp}/DEBIAN/md5sums");
 			}
 		}
 	}
diff --git a/dh_strip b/dh_strip
index bcc8e09..4de68e8 100755
--- a/dh_strip
+++ b/dh_strip
@@ -285,7 +285,7 @@ sub make_debug {
 	}
 
 	# No reason for this to be executable.
-	reset_perm_and_owner('0644', $debug_path);
+	reset_perm_and_owner(0644, $debug_path);
 	return $debug_path;
 }
 

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




More information about the debhelper-devel mailing list