From dbf14b11a1c911e6832e5518ae9c3e406245edaa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 17 Jun 2024 18:37:30 +0200 Subject: Merging upstream version 13.16. Signed-off-by: Daniel Baumann --- dh_installtmpfiles | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'dh_installtmpfiles') diff --git a/dh_installtmpfiles b/dh_installtmpfiles index aa5ab72..70dbc5a 100755 --- a/dh_installtmpfiles +++ b/dh_installtmpfiles @@ -28,6 +28,12 @@ and generates F code blocks for activating the tmpfiles.d configuration when the package is installed. These snippets are added to the maintainer scripts by L. +In compat 14+, tmpfiles.d files are copied into the F script, and +they are used with systemd-tmpfiles --remove after the package is removed +and --purge when the package is purged. This allows one to use the +tmpfiles.d mechanism to clean up files that are no longer needed after a +package has been removed/purged. + =head1 OPTIONS @@ -35,7 +41,7 @@ to the maintainer scripts by L. =item B<--name=>I -This option controls both a prefix used for lookng up maintainer provided +This option controls both a prefix used for looking up maintainer provided tmpfiles.d configuration files (those mentioned in the L section) and also the base name used for the installed version of the file. @@ -105,20 +111,54 @@ foreach my $package (@{$dh{DOPACKAGES}}) { foreach my $package (@{$dh{DOPACKAGES}}) { my $tmpdir = tmpdir($package); my @tmpfiles; + my @purge; + my @remove; my @dirs = grep { -d } map { "${tmpdir}/$_" } qw(usr/lib/tmpfiles.d etc/tmpfiles.d); find({ wanted => sub { + my $lines; my $name = $File::Find::name; return if not -f $name or not $name =~ m{[.]conf$}; - push(@tmpfiles, basename($name)); }, + push(@tmpfiles, basename($name)); + + # We copy the needed lines to the postrm, as the tmpfiles.d files + # will be gone by the time the remove/purge postscript is run. + if (! compat(13) && (! $dh{NO_PURGE} || ! $dh{NO_REMOVE})) { + open(my $fd, '<', $name) or error("open($name) failed: $!"); + { + local $/; + $lines = <$fd>; + } + close($fd); + + chomp $lines; + + if ($lines) { + push(@purge, $lines); + push(@remove, $lines); + } + } + }, no_chdir => 1, }, @dirs) if @dirs; if (@tmpfiles) { autoscript($package, 'postinst', 'postinst-init-tmpfiles', { 'TMPFILES' => join(' ', uniq(sort(@tmpfiles))) }); } + + if (@remove) { + autoscript($package, 'postrm', 'postrm-init-tmpfiles-remove', { + 'TMPFILES_REMOVE' => join("\n", @remove), + }); + } + + if (@purge) { + autoscript($package, 'postrm', 'postrm-init-tmpfiles-purge', { + 'TMPFILES_PURGE' => join("\n", @purge), + }); + } } =head1 SEE ALSO -- cgit v1.2.3