[debhelper-devel] [debhelper] 01/05: Dh_Lib: Add rm_files and make_symlink_raw_target

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

    Dh_Lib: Add rm_files and make_symlink_raw_target
    
    Without fork+exec and manual error checking, they can remove files
    (ignoring files that don't exist) and create a raw symlink.
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index afb5643..8b64e03 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -31,6 +31,7 @@ my %NAMED_COMPAT_LEVELS = (
 	'beta-tester'          => BETA_TESTER_COMPAT,
 );
 
+use Errno qw(ENOENT);
 use Exporter qw(import);
 use vars qw(@EXPORT %dh);
 @EXPORT=qw(&init &doit &doit_noerror &complex_doit &verbose_print &error
@@ -53,6 +54,7 @@ use vars qw(@EXPORT %dh);
 	    &open_gz &reset_perm_and_owner &deprecated_functionality
 	    &log_installed_files &buildarch &rename_path
 	    &on_pkgs_in_parallel &on_selected_pkgs_in_parallel
+	    &rm_files &make_symlink_raw_target
 );
 
 # The Makefile changes this if debhelper is installed in a PREFIX.
@@ -1280,6 +1282,29 @@ sub debhelper_script_subst {
 	}
 }
 
+sub rm_files {
+	my @files = @_;
+	verbose_print('rm -f ' . escape_shell(@files))
+		if $dh{VERBOSE};
+	return 1 if $dh{NO_ACT};
+	for my $file (@files) {
+		if (not unlink($file) and $! != ENOENT) {
+			error("unlink $file failed: $!");
+		}
+	}
+	return 1;
+}
+
+sub make_symlink_raw_target {
+	my ($src, $dest) = @_;
+	verbose_print('ln -s ' . escape_shell($src, $dest))
+		if $dh{VERBOSE};
+	return 1 if $dh{NO_ACT};
+	if (not symlink($src, $dest)) {
+		error("symlink($src, $dest) failed: $!");
+	}
+	return 1;
+}
 
 # make_symlink($dest, $src[, $tmp]) creates a symlink from  $dest -> $src.
 # if $tmp is given, $dest will be created within it.

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