diff options
-rw-r--r-- | debian/init-system-helpers.postinst | 6 | ||||
-rwxr-xr-x | script/deb-systemd-helper | 20 | ||||
-rw-r--r-- | t/001-deb-systemd-helper.t | 17 |
3 files changed, 37 insertions, 6 deletions
diff --git a/debian/init-system-helpers.postinst b/debian/init-system-helpers.postinst index cbea846..6afcaec 100644 --- a/debian/init-system-helpers.postinst +++ b/debian/init-system-helpers.postinst @@ -9,12 +9,6 @@ if dpkg --compare-versions "$2" lt "1.9"; then fi fi -if dpkg --compare-versions "$2" lt "1.10"; then - if [ -d /var/lib/systemd/deb-systemd-helper-masked ]; then - rm -rf /var/lib/systemd/deb-systemd-helper-masked - fi -fi - #DEBHELPER# exit 0 diff --git a/script/deb-systemd-helper b/script/deb-systemd-helper index 92290ae..3adcd9d 100755 --- a/script/deb-systemd-helper +++ b/script/deb-systemd-helper @@ -93,6 +93,7 @@ use Data::Dumper; my $quiet = 0; my $enabled_state_dir = '/var/lib/systemd/deb-systemd-helper-enabled'; +my $masked_state_dir = '/var/lib/systemd/deb-systemd-helper-masked'; # Globals are bad, but in this specific case, it really makes things much # easier to write and understand. @@ -386,6 +387,16 @@ sub mask_service { symlink('/dev/null', $mask_link) or error("unable to link $mask_link to /dev/null: $!"); $changed_sth = 1; + + my $statefile = $mask_link; + $statefile =~ s,^/etc/systemd/system/,$masked_state_dir/,; + + # Store the fact that we masked this service, so that we can unmask it on + # installation time. We cannot unconditionally unmask because that would + # interfere with the user’s decision to mask a service. + make_path(dirname($statefile)); + open(my $fh, '>>', $statefile); + close($fh); } sub unmask_service { @@ -401,10 +412,19 @@ sub unmask_service { return; } + my $statefile = $mask_link; + $statefile =~ s,^/etc/systemd/system/,$masked_state_dir/,; + + if (! -e $statefile) { + debug "Not unmasking $mask_link because the state file $statefile does not exist"; + return; + } + print STDERR "rm '$mask_link'\n" unless $quiet; unlink($mask_link) or error("unable to remove $mask_link: $!"); $changed_sth = 1; + unlink($statefile); } my $result = GetOptions( diff --git a/t/001-deb-systemd-helper.t b/t/001-deb-systemd-helper.t index 5bb9ecd..4d814ea 100644 --- a/t/001-deb-systemd-helper.t +++ b/t/001-deb-systemd-helper.t @@ -191,4 +191,21 @@ is(readlink($mask_path), '/dev/null', 'service masked'); $retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit"); ok(! -e $mask_path, 'symlink no longer exists'); +# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +# ┃ Verify “mask”/unmask don’t do anything when the user already masked. ┃ +# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +ok(! -l $mask_path, 'mask link does not exist yet'); +symlink('/dev/null', $mask_path); +ok(-l $mask_path, 'mask link exists'); +is(readlink($mask_path), '/dev/null', 'service masked'); + +$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh mask $random_unit"); +ok(-l $mask_path, 'mask link exists'); +is(readlink($mask_path), '/dev/null', 'service still masked'); + +$retval = system("DPKG_MAINTSCRIPT_PACKAGE=test $dsh unmask $random_unit"); +ok(-l $mask_path, 'mask link exists'); +is(readlink($mask_path), '/dev/null', 'service still masked'); + done_testing; |