Skip to content

Commit 41064a3

Browse files
poetteringbluca
authored andcommitted
tmpfiles: insist on at least one configuration file being specified on --purge
Also, extend the man page explanation substantially, matching more closely what --create says. Fixes: systemd#33349
1 parent edeceb8 commit 41064a3

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

man/systemd-tmpfiles.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,26 @@
151151

152152
<varlistentry>
153153
<term><option>--purge</option></term>
154-
<listitem><para>If this option is passed, all files and directories created by a
155-
<filename>tmpfiles.d/</filename> entry will be deleted. Keep in mind that by default,
156-
<filename>/home</filename> is created by <command>systemd-tmpfiles</command>
157-
(see <filename>/usr/lib/tmpfiles.d/home.conf</filename>). Therefore it is recommended
158-
to first run <command>systemd-tmpfiles --dry-run --purge</command> to be certain which files
159-
and directories will be deleted.</para>
154+
155+
<listitem><para>If this option is passed, all files and directories marked for
156+
<emphasis>creation</emphasis> by the <filename>tmpfiles.d/</filename> files specified on the command
157+
line will be <emphasis>deleted</emphasis>. Specifically, this acts on all files and directories
158+
marked with <varname>f</varname>, <varname>F</varname>, <varname>d</varname>, <varname>D</varname>,
159+
<varname>v</varname>, <varname>q</varname>, <varname>Q</varname>, <varname>p</varname>,
160+
<varname>L</varname>, <varname>c</varname>, <varname>b</varname>, <varname>C</varname>,
161+
<varname>w</varname>, <varname>e</varname>. If this switch is used at least one
162+
<filename>tmpfiles.d/</filename> file (or <filename>-</filename> for standard input) must be
163+
specified on the command line or the invocation will be refused, for safety reasons (as otherwise
164+
much of the installed system files might be removed).</para>
165+
166+
<para>The primary usecase for this option is to automatically remove files and directories that
167+
originally have been created on behalf of an installed packaged at package removal time.</para>
168+
169+
<para>It is recommended to first run this command in combination with <option>--dry-run</option>
170+
(see below) to verify which files and directories will be deleted.</para>
171+
172+
<para><emphasis>Warning!</emphasis> This is is usually not the command you want! In most cases
173+
<option>--remove</option> is what you are looking for.</para>
160174

161175
<xi:include href="version-info.xml" xpointer="v256"/></listitem>
162176
</varlistentry>

src/tmpfiles/tmpfiles.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4344,6 +4344,10 @@ static int parse_argv(int argc, char *argv[]) {
43444344
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
43454345
"You need to specify at least one of --clean, --create, --remove, or --purge.");
43464346

4347+
if (FLAGS_SET(arg_operation, OPERATION_PURGE) && optind >= argc)
4348+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
4349+
"Refusing --purge without specification of a configuration file.");
4350+
43474351
if (arg_replace && arg_cat_flags != CAT_CONFIG_OFF)
43484352
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
43494353
"Option --replace= is not supported with --cat-config/--tldr.");

0 commit comments

Comments
 (0)