CHANGES WITH 257 in spe:
+ Incompatible changes:
+
+ * The --purge switch of systemd-tmpfiles (which was added in v256) has
+ been reworked: it will now only apply to tmpfiles.d/ lines marked
+ with the new "$" flag. This is an incompatible change, and means any
+ tmpfiles.d/ files which shall be used together with --purge need to
+ be updated accordingly. This change has been made to make it harder
+ to accidentally delete too many files when using --purge incorrectly.
+
Announcements of Future Feature Removals and Incompatible Changes:
* Support for automatic flushing of the nscd user/group database caches
<varlistentry>
<term><option>--purge</option></term>
- <listitem><para>If this option is passed, all files and directories marked for
- <emphasis>creation</emphasis> by the <filename>tmpfiles.d/</filename> files specified on the command
- line will be <emphasis>deleted</emphasis>. Specifically, this acts on all files and directories
- marked with <varname>f</varname>, <varname>F</varname>, <varname>d</varname>, <varname>D</varname>,
+ <listitem><para>If this option is passed, all files and directories declared for
+ <emphasis>creation</emphasis> and marked with the <literal>$</literal> character by the
+ <filename>tmpfiles.d/</filename> files specified on the command line will be
+ <emphasis>deleted</emphasis>. Specifically, this acts on all files and directories marked with
+ <varname>f</varname>, <varname>F</varname>, <varname>d</varname>, <varname>D</varname>,
<varname>v</varname>, <varname>q</varname>, <varname>Q</varname>, <varname>p</varname>,
<varname>L</varname>, <varname>c</varname>, <varname>b</varname>, <varname>C</varname>,
<varname>w</varname>, <varname>e</varname>. If this switch is used at least one
service, the line is silently skipped. If <literal>^</literal> and <literal>~</literal> are combined
Base64 decoding is applied to the credential contents.</para>
+ <para>If the dollar sign (<literal>$</literal>) is used, the file becomes subject to removal when
+ <command>systemd-tmpfiles</command> is invoked with the <option>--purge</option> switch. Lines without
+ this character are unaffected by that switch.</para>
+
<para>Note that for all line types that result in creation of any kind of file node
(i.e. <varname>f</varname>,
<varname>d</varname>/<varname>D</varname>/<varname>v</varname>/<varname>q</varname>/<varname>Q</varname>,
bool try_replace:1;
+ bool purge:1;
+
OperationMask done;
} Item;
if (!needs_purge(i->type))
return 0;
+ if (!i->purge)
+ return 0;
+
log_debug("Running purge action for entry %c %s", (char) i->type, i->path);
if (needs_glob(i->type))
ItemArray *existing;
OrderedHashmap *h;
bool append_or_force = false, boot = false, allow_failure = false, try_replace = false,
- unbase64 = false, from_cred = false, missing_user_or_group = false;
+ unbase64 = false, from_cred = false, missing_user_or_group = false, purge = false;
int r;
assert(fname);
unbase64 = true;
else if (action[pos] == '^' && !from_cred)
from_cred = true;
+ else if (action[pos] == '$' && !purge)
+ purge = true;
else {
*invalid_config = true;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
i.append_or_force = append_or_force;
i.allow_failure = allow_failure;
i.try_replace = try_replace;
+ i.purge = purge;
r = specifier_printf(path, PATH_MAX-1, specifier_table, arg_root, NULL, &i.path);
if (ERRNO_IS_NOINFO(r))
"Unknown command type '%c'.", (char) i.type);
}
+ if (i.purge && !needs_purge(i.type)) {
+ *invalid_config = true;
+ return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
+ "Purge flag '$' combined with line type '%c' which does not support purging.", (char) i.type);
+ }
+
if (!should_include_path(i.path))
return 0;
export SYSTEMD_LOG_LEVEL=debug
c='
-d /tmp/somedir
-f /tmp/somedir/somefile - - - - baz
+d$ /tmp/somedir
+f$ /tmp/somedir/somefile - - - - baz
+f /tmp/someotherfile - - - - qux
'
systemd-tmpfiles --create - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile
+grep -q qux /tmp/someotherfile
systemd-tmpfiles --purge --dry-run - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile
+grep -q qux /tmp/someotherfile
systemd-tmpfiles --purge - <<<"$c"
test ! -f /tmp/somedir/somefile
test ! -d /tmp/somedir/
+grep -q qux /tmp/someotherfile
systemd-tmpfiles --create --purge --dry-run - <<<"$c"
test ! -f /tmp/somedir/somefile
test ! -d /tmp/somedir/
+grep -q qux /tmp/someotherfile
systemd-tmpfiles --create --purge - <<<"$c"
test -f /tmp/somedir/somefile
grep -q baz /tmp/somedir/somefile
+grep -q qux /tmp/someotherfile
+
+systemd-tmpfiles --purge - <<<"$c"
+test ! -f /tmp/somedir/somefile
+test ! -d /tmp/somedir/
+grep -q qux /tmp/someotherfile
+
+rm /tmp/someotherfile