[debhelper-devel] [debhelper] 04/05: make_symlink: Avoid unnecessary stat calls

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 a9d3cafa1bd5c1ed40e3382e8e51c5c44929880c
Author: Niels Thykier <niels at thykier.net>
Date:   Mon Jun 26 07:44:59 2017 +0000

    make_symlink: Avoid unnecessary stat calls
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 20 +++++++++++++-------
 debian/changelog           |  2 ++
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index c3f3c4a..e84222b 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -1322,9 +1322,7 @@ sub make_symlink{
 		return;
 	}
 
-	# Make sure the directory the link will be in exists.
-	my $basedir=dirname("$tmp/$dest");
-	install_dir($basedir);
+
 
 	# Policy says that if the link is all within one toplevel
 	# directory, it should be relative. If it's between
@@ -1354,11 +1352,19 @@ sub make_symlink{
 		$src="/$src";
 	}
 
-	if (-d "$tmp/$dest" && ! -l "$tmp/$dest") {
-		error("link destination $tmp/$dest is a directory");
+	my $full_dest = "$tmp/$dest";
+	if ( -l $full_dest ) {
+		# All ok - we can always replace a link, and target directory must exists
+	} elsif (-d _) {
+		# We cannot replace a directory though
+		error("link destination $full_dest is a directory");
+	} else {
+		# Make sure the directory the link will be in exists.
+		my $basedir=dirname($full_dest);
+		install_dir($basedir);
 	}
-	rm_files("$tmp/$dest");
-	make_symlink_raw_target($src, "$tmp/$dest");
+	rm_files($full_dest);
+	make_symlink_raw_target($src, $full_dest);
 }
 
 # _expand_path expands all path "." and ".." components, but doesn't
diff --git a/debian/changelog b/debian/changelog
index cbdce7a..bd95f55 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,6 +16,8 @@ debhelper (10.5.1) UNRELEASED; urgency=medium
   * dh_md5sums: Ditto.
   * dh_installdocs: Avoid a fork+exec for ln -s.
   * dh_strip: Ditto.
+  * Dh_Lib: Avoid 1-2 stat calls in make_symlink by reusing existing
+    stat calls.
 
  -- Niels Thykier <niels at thykier.net>  Sun, 25 Jun 2017 18:02:30 +0000
 

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