[debhelper-devel] [debhelper] 01/01: Dh_Lib: Add a reset_perm_and_owner function

Niels Thykier nthykier at moszumanska.debian.org
Sun Oct 2 20:41:56 UTC 2016


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

nthykier pushed a commit to branch master
in repository debhelper.

commit 580bc09d41ddc8542515f50d40ff8c8477711d3d
Author: Niels Thykier <niels at thykier.net>
Date:   Sun Oct 2 20:41:26 2016 +0000

    Dh_Lib: Add a reset_perm_and_owner function
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 13 ++++++++-----
 dh_bugfiles                |  4 ++--
 dh_fixperms                |  4 ++--
 dh_gencontrol              |  7 ++-----
 dh_installchangelogs       |  3 +--
 dh_installdeb              |  2 +-
 dh_installman              |  2 +-
 dh_makeshlibs              |  3 +--
 dh_md5sums                 |  6 ++----
 dh_strip                   |  2 +-
 doc/PROGRAMMING            | 10 ++++++++++
 11 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 3ecd6e6..121dc04 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -49,7 +49,7 @@ use vars qw(@EXPORT %dh);
 	    &get_source_date_epoch &is_cross_compiling
 	    &generated_file &autotrigger &package_section
 	    &restore_file_on_clean &restore_all_files
-	    &open_gz
+	    &open_gz &reset_perm_and_owner
 );
 
 # The Makefile changes this if debhelper is installed in a PREFIX.
@@ -324,6 +324,11 @@ sub install_dir {
 	my @to_create = grep { not -d $_ } @_;
 	doit('install', '-d', @to_create) if @to_create;
 }
+sub reset_perm_and_owner {
+	my ($mode, @paths) = @_;
+	doit('chmod', $mode, '--', @paths);
+	doit('chown', '0:0', '--', @paths);
+}
 
 # Run a command that may have a huge number of arguments, like xargs does.
 # Pass in a reference to an array containing the arguments, and then other
@@ -1101,14 +1106,12 @@ sub debhelper_script_subst {
 			# Just get rid of any #DEBHELPER# in the script.
 			complex_doit("sed s/#DEBHELPER#// < $file > $tmp/DEBIAN/$script");
 		}
-		doit("chown","0:0","$tmp/DEBIAN/$script");
-		doit("chmod","0755","$tmp/DEBIAN/$script");
+		reset_perm_and_owner('0755', "$tmp/DEBIAN/$script");
 	}
 	elsif ( -f "debian/$ext$script.debhelper" ) {
 		complex_doit("printf '#!/bin/sh\nset -e\n' > $tmp/DEBIAN/$script");
 		complex_doit("cat debian/$ext$script.debhelper >> $tmp/DEBIAN/$script");
-		doit("chown","0:0","$tmp/DEBIAN/$script");
-		doit("chmod","0755","$tmp/DEBIAN/$script");
+		reset_perm_and_owner('0755', "$tmp/DEBIAN/$script");
 	}
 }
 
diff --git a/dh_bugfiles b/dh_bugfiles
index dd694da..51fe1ff 100755
--- a/dh_bugfiles
+++ b/dh_bugfiles
@@ -121,10 +121,10 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	
 	# Ensure that the bug script is executable
 	if (-f $dir) {
-		chmod 0755, $dir;
+		reset_perm_and_owner('0755', $dir);
 	}
 	elsif (-f "$dir/script") {
-		chmod 0755, "$dir/script";
+		reset_perm_and_owner('0755', "$dir/script");
 	}
 }
 
diff --git a/dh_fixperms b/dh_fixperms
index 79c2b18..fafe451 100755
--- a/dh_fixperms
+++ b/dh_fixperms
@@ -124,10 +124,10 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			"! -name 'script' $find_options -print0",
 			"2>/dev/null | xargs -0r chmod 644");
 		if ( -f "$tmp/usr/share/bug/$package/script" ) {
-			doit('chmod', '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" ) {
-		doit('chmod', '0755', "$tmp/usr/share/bug/$package");
+		reset_perm_and_owner('0755', "$tmp/usr/share/bug/$package");
 	}
 
 	# Lintian overrides should never be executable, too.
diff --git a/dh_gencontrol b/dh_gencontrol
index 887d35c..4edb065 100755
--- a/dh_gencontrol
+++ b/dh_gencontrol
@@ -126,8 +126,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		doit("dpkg-gencontrol", "-p${package}", "-l$changelog", "-T$substvars",
 			"-P${dbgsym_tmp}",@{$dh{U_PARAMS}}, @dbgsym_options);
 
-		doit("chmod","0644","${dbgsym_tmp}/DEBIAN/control");
-		doit("chown","0:0","${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
@@ -141,9 +140,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 
 	# This chmod is only necessary if the user sets the umask to
 	# something odd.
-	doit("chmod","0644","$tmp/DEBIAN/control");
-	
-	doit("chown","0:0","$tmp/DEBIAN/control");
+	reset_perm_and_owner('0644', "${tmp}/DEBIAN/control");
 }
 
 sub read_dbgsym_file {
diff --git a/dh_installchangelogs b/dh_installchangelogs
index 9f0563e..4aaef0b 100755
--- a/dh_installchangelogs
+++ b/dh_installchangelogs
@@ -224,8 +224,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			$link_to='changelog.html';
 			if (! defined $upstream_text) {
 				complex_doit("echo 'See changelog.html.gz' > $base/changelog");
-				doit("chmod","644","$base/changelog");
-				doit("chown","0:0","$base/changelog");
+				reset_perm_and_owner('0644',"$base/changelog");
 			}
 		}
 		if ($dh{K_FLAG}) {
diff --git a/dh_installdeb b/dh_installdeb
index 7ba846c..0507617 100755
--- a/dh_installdeb
+++ b/dh_installdeb
@@ -182,7 +182,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			doit("rm","-f","$tmp/DEBIAN/conffiles");
 		}
 		else {
-			doit("chmod","0644","$tmp/DEBIAN/conffiles");
+			reset_perm_and_owner('0644', "$tmp/DEBIAN/conffiles");
 		}
 	}
 }
diff --git a/dh_installman b/dh_installman
index 78faf13..bbea82e 100755
--- a/dh_installman
+++ b/dh_installman
@@ -210,7 +210,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 				complex_doit "man --recode UTF-8 ./\Q$orig\E > \Q$tmp\E";
 				# recode uncompresses compressed pages
 				doit "rm", "-f", $orig if s/\.(gz|Z)$//;
-				doit "chmod", 644, $tmp;
+				reset_perm_and_owner('0755' $tmp);
 				doit "mv", "-f", $tmp, $_;
 			}, "$tmp/$dir");
 		}
diff --git a/dh_makeshlibs b/dh_makeshlibs
index 45f2946..7fb5ac1 100755
--- a/dh_makeshlibs
+++ b/dh_makeshlibs
@@ -239,8 +239,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	}
 
 	if (-e "$tmp/DEBIAN/shlibs") {
-		doit("chmod","0644","$tmp/DEBIAN/shlibs");
-		doit("chown","0:0","$tmp/DEBIAN/shlibs");
+		reset_perm_and_owner('0644', "$tmp/DEBIAN/shlibs");
 	}
 
 	# dpkg-gensymbols files
diff --git a/dh_md5sums b/dh_md5sums
index d4e9ff3..b4b3c92 100755
--- a/dh_md5sums
+++ b/dh_md5sums
@@ -83,8 +83,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		doit("rm","-f","$tmp/DEBIAN/md5sums");
 	}
 	else {
-		doit("chmod", "0644", "$tmp/DEBIAN/md5sums");
-		doit("chown", "0:0", "$tmp/DEBIAN/md5sums");
+		reset_perm_and_owner('0644', "$tmp/DEBIAN/md5sums");
 	}
 	if ( -d $dbgsym_tmp) {
 		install_dir("${dbgsym_tmp}/DEBIAN");
@@ -96,8 +95,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			doit('rm', '-f', "${dbgsym_tmp}/DEBIAN/md5sums");
 		}
 		else {
-			doit('chmod', '0644', "${dbgsym_tmp}/DEBIAN/md5sums");
-			doit('chown', '0:0', "${dbgsym_tmp}/DEBIAN/md5sums");
+			reset_perm_and_owner('0644', "${dbgsym_tmp}/DEBIAN/md5sums");
 		}
 	}
 }
diff --git a/dh_strip b/dh_strip
index 7a16750..9ecfa41 100755
--- a/dh_strip
+++ b/dh_strip
@@ -283,7 +283,7 @@ sub make_debug {
 	}
 
 	# No reason for this to be executable.
-	doit("chmod", "0644", $debug_path);
+	reset_perm_and_owner('0644', $debug_path);
 	return $debug_path;
 }
 
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index 4d1e315..eb06372 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -324,6 +324,16 @@ install_lib($src, $dest)
 	Installs a library at the path $src into $dest.  The parent
 	dir of $dest must exist (can be created with install_dir).
 	This is intended for installing libraries.
+reset_perm_and_owner($mode, $path...)
+	Resets the ownership and mode (POSIX permissions) of $path
+	This is useful for files created directly by the script, but
+	it not necessary for files installed via the install_*
+	functions.
+	The file owner and group is set to "root:root".  The change
+	is only done on the exact paths listed (i.e. it is *not*
+	recursive).
+	To avoid issue, please pass mode as a string (i.e. '0755'
+	rather than 0755).
 open_gz($file)
 	Open $file, read from it as a gzip-compressed file and return
 	the file handle.

-- 
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