[debhelper-devel] [debhelper] 02/05: Avoid fork+exec for rm -f and ln -s in non-deprecated tools

Niels Thykier nthykier at moszumanska.debian.org
Mon Jun 26 07:56:08 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 ee8fd59af61fa4739cdd536ecbb492cc8520df40
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Jun 26 07:35:18 2017 +0000

    Avoid fork+exec for rm -f and ln -s in non-deprecated tools
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 4 ++--
 dh                         | 5 ++++-
 dh_clean                   | 8 +++++---
 dh_compress                | 6 +++---
 dh_installdeb              | 2 +-
 dh_installdocs             | 2 +-
 dh_installman              | 6 +++---
 dh_makeshlibs              | 4 ++--
 dh_md5sums                 | 4 ++--
 dh_strip                   | 2 +-
 10 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 8b64e03..c3f3c4a 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -1357,8 +1357,8 @@ sub make_symlink{
 	if (-d "$tmp/$dest" && ! -l "$tmp/$dest") {
 		error("link destination $tmp/$dest is a directory");
 	}
-	doit("rm", "-f", "$tmp/$dest");
-	doit("ln","-sf", $src, "$tmp/$dest");
+	rm_files("$tmp/$dest");
+	make_symlink_raw_target($src, "$tmp/$dest");
 }
 
 # _expand_path expands all path "." and ".." components, but doesn't
diff --git a/dh b/dh
index ee8c6cf..2f63a96 100755
--- a/dh
+++ b/dh
@@ -851,7 +851,10 @@ sub run_override {
 
 	# Discard any override log files before calling the override
 	# target
-	complex_doit("rm","-f","debian/*.debhelper.log") if not compat(9);
+	if (not compat(9)) {
+		my @files = glob('debian/*.debhelper.log');
+		rm_files(@files) if @files;
+	}
 	# This passes the options through to commands called
 	# inside the target.
 	$ENV{DH_INTERNAL_OPTIONS}=join("\x1e", @options);
diff --git a/dh_clean b/dh_clean
index 47f0434..f50be30 100755
--- a/dh_clean
+++ b/dh_clean
@@ -86,7 +86,7 @@ if ($dh{K_FLAG}) {
 }
 
 # Remove the debhelper stamp file
-doit('rm', '-f', 'debian/debhelper-build-stamp') if not $dh{D_FLAG};
+rm_files('debian/debhelper-build-stamp') if not $dh{D_FLAG};
 
 my (@clean_files, @clean_dirs);
 
@@ -120,7 +120,8 @@ if (not $dh{D_FLAG}) {
 
 # Remove all debhelper logs.
 if (! $dh{D_FLAG} && ! $dh{K_FLAG}) {
-	complex_doit("rm","-f","debian/*.debhelper.log");
+	my @logs = glob('debian/*.debhelper.log');
+	rm_files(@logs) if @logs;
 }
 
 if (! $dh{D_FLAG}) {
@@ -171,7 +172,8 @@ doit('rm', '-rf', 'debian/tmp') if -x 'debian/tmp' &&
                                    ! excludefile("debian/tmp");
 
 if (!compat(6) && !$dh{K_FLAG}) {
-	complex_doit('rm -f *-stamp');
+	my @stamp_files = glob('*-stamp');
+	rm_files(@stamp_files) if @stamp_files;
 }
 
 =head1 SEE ALSO
diff --git a/dh_compress b/dh_compress
index c3def86..89c23f8 100755
--- a/dh_compress
+++ b/dh_compress
@@ -192,7 +192,7 @@ on_pkgs_in_parallel {
 		# they are again.
 		foreach (keys %hardlinks) {
 			# Remove old file.
-			doit("rm","-f","$_");
+			rm_files($_);
 			# Make new hardlink.
 			doit("ln","$hardlinks{$_}.gz","$_.gz");
 		}
@@ -212,8 +212,8 @@ on_pkgs_in_parallel {
 				my ($directory) = $link =~ m:(.*)/:;
 				my $linkval = readlink($link);
 				if (! -e "$directory/$linkval" && -e "$directory/$linkval.gz") {
-					doit("rm","-f",$link);
-					doit("ln","-sf","$linkval.gz","$link.gz");
+					rm_files($link);
+					make_symlink_raw_target("$linkval.gz","$link.gz");
 					delete $links{$link};
 					$changed++;
 				}
diff --git a/dh_installdeb b/dh_installdeb
index 0507617..09d0426 100755
--- a/dh_installdeb
+++ b/dh_installdeb
@@ -179,7 +179,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		complex_doit("find $tmp/etc -type f -printf '/etc/%P\n' | LC_ALL=C sort >> $tmp/DEBIAN/conffiles");
 		# Anything found?
 		if (-z "$tmp/DEBIAN/conffiles") {
-			doit("rm","-f","$tmp/DEBIAN/conffiles");
+			rm_files("$tmp/DEBIAN/conffiles");
 		}
 		else {
 			reset_perm_and_owner('0644', "$tmp/DEBIAN/conffiles");
diff --git a/dh_installdocs b/dh_installdocs
index 5d82ea5..465a74d 100755
--- a/dh_installdocs
+++ b/dh_installdocs
@@ -207,7 +207,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		# necessary.
 		if (! -d "$tmp/usr/share/doc/$package" &&
 		    ! -l "$tmp/usr/share/doc/$package") {
-			doit("ln", "-sf", $dh{LINK_DOC}, "$tmp/usr/share/doc/$package");
+			make_symlink_raw_target($dh{LINK_DOC}, "$tmp/usr/share/doc/$package");
 			# Policy says that if you make your documentation
 			# directory a symlink, then you have to depend on
 			# the target.
diff --git a/dh_installman b/dh_installman
index 59514ef..ec55873 100755
--- a/dh_installman
+++ b/dh_installman
@@ -229,8 +229,8 @@ on_selected_pkgs_in_parallel(\@all_packages, sub {
 		}
 		foreach my $sofile (@sofiles) {
 			my $sodest = shift(@sodests);
-			doit "rm", "-f", $sofile;
-			doit "ln", "-sf", $sodest, $sofile;
+			rm_files($sofile);
+			make_symlink_raw_target($sodest, $sofile);
 		}
 
 		# Now utf-8 conversion.
@@ -243,7 +243,7 @@ on_selected_pkgs_in_parallel(\@all_packages, sub {
 						my ($tmp, $orig) = ($_.".new", $_);
 						complex_doit "man --recode UTF-8 ./\Q$orig\E > \Q$tmp\E";
 						# recode uncompresses compressed pages
-						doit "rm", "-f", $orig if s/\.(gz|Z)$//;
+						rm_files($orig) if s/\.(gz|Z)$//;
 						doit "mv", "-f", $tmp, $_;
 						# Schedule a permission reset
 						push(@files, "${File::Find::dir}/${_}");
diff --git a/dh_makeshlibs b/dh_makeshlibs
index 4f5c8b6..0dc2027 100755
--- a/dh_makeshlibs
+++ b/dh_makeshlibs
@@ -149,7 +149,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	my $need_ldconfig = 0;
 	my $shlibs_file = pkgfile($package, 'shlibs');
 
-	doit("rm", "-f", "$tmp/DEBIAN/shlibs");
+	rm_files("$tmp/DEBIAN/shlibs");
 
 	# So, we look for files or links to existing files with names that
 	# match "*.so.*". And we only look at real files not
@@ -263,7 +263,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			) && $ok;
 
 		if (-f "$tmp/DEBIAN/symbols" and -s _ == 0) {
-			doit("rm", "-f", "$tmp/DEBIAN/symbols");
+			rm_files("$tmp/DEBIAN/symbols");
 		} elsif ($unversioned_so) {
 			# There are a few "special" libraries (e.g. nss/nspr)
 			# which do not have versioned SONAMES.  However the
diff --git a/dh_md5sums b/dh_md5sums
index b91b2d6..344c9ad 100755
--- a/dh_md5sums
+++ b/dh_md5sums
@@ -82,7 +82,7 @@ on_pkgs_in_parallel {
 			q{perl -pe 'if (s@^\\\\@@) { s/\\\\\\\\/\\\\/g; }' > DEBIAN/md5sums) >/dev/null});
 		# If the file's empty, no reason to waste inodes on it.
 		if (-z "$tmp/DEBIAN/md5sums") {
-			doit("rm","-f","$tmp/DEBIAN/md5sums");
+			rm_files("$tmp/DEBIAN/md5sums");
 		}
 		else {
 			reset_perm_and_owner('0644', "$tmp/DEBIAN/md5sums");
@@ -95,7 +95,7 @@ on_pkgs_in_parallel {
 				q{perl -pe 'if (s@^\\\\@@) { s/\\\\\\\\/\\\\/g; }' > DEBIAN/md5sums) >/dev/null});
 			# If the file's empty, no reason to waste inodes on it.
 			if (-z "${dbgsym_tmp}/DEBIAN/md5sums") {
-				doit('rm', '-f', "${dbgsym_tmp}/DEBIAN/md5sums");
+				rm_files("${dbgsym_tmp}/DEBIAN/md5sums");
 			}
 			else {
 				reset_perm_and_owner('0644', "${dbgsym_tmp}/DEBIAN/md5sums");
diff --git a/dh_strip b/dh_strip
index 738bcc5..a7efc2d 100755
--- a/dh_strip
+++ b/dh_strip
@@ -368,7 +368,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 		my $doc_symlink = "${dbgsym_docdir}/${package}-dbgsym";
 		if ( not -l $doc_symlink and not -e $doc_symlink ) {
 			install_dir($dbgsym_docdir);
-			doit('ln', '-s', $package, $doc_symlink);
+			make_symlink_raw_target($package, $doc_symlink);
 		}
 		if ($dh{MIGRATE_DBGSYM}) {
 			my $path = "debian/.debhelper/${package}/dbgsym-migration";

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