[debhelper-devel] [debhelper] 01/01: dh_systemd_*: Fix incorrect error for "missing" files

Niels Thykier nthykier at moszumanska.debian.org
Sat Oct 21 12:22:52 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 740c628a1e571acded7e2aac5d6e7058e61da37f
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Oct 21 12:20:59 2017 +0000

    dh_systemd_*: Fix incorrect error for "missing" files
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 debian/changelog  |  4 ++++
 dh_systemd_enable | 23 +++++++++++++++++++++--
 dh_systemd_start  | 22 +++++++++++++++++++++-
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 3e4db40..3856b47 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,10 @@ debhelper (10.9.3) UNRELEASED; urgency=medium
   * dh_installinit: In compat 12, error out if an upstart init file
     is provided with a reminder message about how to remove the
     obsolete conffile.  (Closes: #876453)
+  * dh_systemd_enable: Permit missing explicitly requested file in
+    package as long as another on being acted on ships it.
+    (Closes: #878911)
+  * dh_systemd_start: Ditto.
 
  -- Niels Thykier <niels at thykier.net>  Sat, 14 Oct 2017 11:18:19 +0000
 
diff --git a/dh_systemd_enable b/dh_systemd_enable
index e2e5add..017bdd2 100755
--- a/dh_systemd_enable
+++ b/dh_systemd_enable
@@ -144,6 +144,9 @@ sub install_unit {
 
 # PROMISE: DH NOOP WITHOUT tmp(lib/systemd/system) mount path service socket target tmpfile timer
 
+my %requested_files = map { basename($_) => 1 } @ARGV;
+my %installed_files;
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
 	my $tmpdir = tmpdir($package);
 	my @installed_units;
@@ -211,7 +214,6 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 
 	for my $name (@args) {
 		my $base = basename($name);
-
 		# Try to make the path absolute, so that the user can call
 		# dh_installsystemd bacula-fd.service
 		if ($base eq $name) {
@@ -220,13 +222,19 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			my ($full) = grep { basename($_) eq $base } @installed_units;
 			if (defined($full)) {
 				$name = $full;
-			} else {
+			} elsif (not exists($requested_files{$base})) {
 				warning(qq|Could not find "$name" in the /lib/systemd/system directory of $package. | .
 					qq|This could be a typo, or using Also= with a service file from another package. | .
 					qq|Please check carefully that this message is harmless.|);
+			} else {
+				# Ignore an explicitly requested file that is missing; happens when we are acting on
+				# multiple packages and only a subset of them have the unit file.
+				next;
 			}
 		}
 
+		$installed_files{$base} = 1 if exists($requested_files{$base});
+
 		# Skip template service files like e.g. getty at .service.
 		# Enabling, disabling, starting or stopping those services
 		# without specifying the instance (e.g. getty at ttyS0.service) is
@@ -259,6 +267,17 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	autoscript($package, 'postrm', 'postrm-systemd', {'UNITFILES' => $unitargs });
 }
 
+if (%requested_files) {
+	my $any_missing = 0;
+	for my $name (sort(keys(%requested_files))) {
+		if (not exists($installed_files{$name})) {
+			warning(qq{Requested unit "$name" but it was not found in any package acted on.});
+			$any_missing = 1;
+		}
+	}
+	error("Could not handle all of the requested services") if $any_missing;
+}
+
 =head1 SEE ALSO
 
 L<dh_systemd_start(1)>, L<debhelper(7)>
diff --git a/dh_systemd_start b/dh_systemd_start
index 362d00a..7f824be 100755
--- a/dh_systemd_start
+++ b/dh_systemd_start
@@ -128,6 +128,9 @@ sub extract_key {
 
 # PROMISE: DH NOOP WITHOUT tmp(lib/systemd/system)
 
+my %requested_files = map { basename($_) => 1 } @ARGV;
+my %installed_files;
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
 	my $tmpdir = tmpdir($package);
 	my @installed_units;
@@ -181,13 +184,19 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 			my ($full) = grep { basename($_) eq $base } @installed_units;
 			if (defined($full)) {
 				$name = $full;
-			} else {
+			} elsif (not exists($requested_files{$base})) {
 				warning(qq|Could not find "$name" in the /lib/systemd/system directory of $package. | .
 					qq|This could be a typo, or using Also= with a service file from another package. | .
 					qq|Please check carefully that this message is harmless.|);
+			} else {
+				# Ignore an explicitly requested file that is missing; happens when we are acting on
+				# multiple packages and only a subset of them have the unit file.
+				next;
 			}
 		}
 
+		$installed_files{$base} = 1 if exists($requested_files{$base});
+
 		# Skip template service files like e.g. getty at .service.
 		# Enabling, disabling, starting or stopping those services
 		# without specifying the instance (e.g. getty at ttyS0.service) is
@@ -246,6 +255,17 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 	}
 }
 
+if (%requested_files) {
+	my $any_missing = 0;
+	for my $name (sort(keys(%requested_files))) {
+		if (not exists($installed_files{$name})) {
+			warning(qq{Requested unit "$name" but it was not found in any package acted on.});
+			$any_missing = 1;
+		}
+	}
+	error("Could not handle all of the requested services") if $any_missing;
+}
+
 =head1 SEE ALSO
 
 L<debhelper(7)>

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