1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

tmpfiles: Allow create symlink on directories (#6039)

Currently if tmpfiles is run with force on symlink creation but there already
exists a directory at that location, the creation will fail. This change
updates the behavior to remove the directory with rm_fr and then attempts to
create the symlink again.
This commit is contained in:
William Douglas 2017-08-09 08:53:03 -07:00 committed by Lennart Poettering
parent 4e7b57eb0e
commit b3f5897f6e
2 changed files with 17 additions and 7 deletions

View File

@ -273,13 +273,14 @@ L /tmp/foobar - - - - /dev/null</programlisting>
<term><varname>L</varname></term> <term><varname>L</varname></term>
<term><varname>L+</varname></term> <term><varname>L+</varname></term>
<listitem><para>Create a symlink if it does not exist <listitem><para>Create a symlink if it does not exist
yet. If suffixed with <varname>+</varname> and a file yet. If suffixed with <varname>+</varname> and a file or
already exists where the symlink is to be created, it will directory already exists where the symlink is to be created,
be removed and be replaced by the symlink. If the argument it will be removed and be replaced by the symlink. If the
is omitted, symlinks to files with the same name residing in argument is omitted, symlinks to files with the same name
the directory <filename>/usr/share/factory/</filename> are residing in the directory
created. Note that permissions and ownership on symlinks <filename>/usr/share/factory/</filename> are created. Note
are ignored.</para></listitem> that permissions and ownership on symlinks are ignored.
</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -1353,6 +1353,15 @@ static int create_item(Item *i) {
r = symlink_atomic(resolved, i->path); r = symlink_atomic(resolved, i->path);
mac_selinux_create_file_clear(); mac_selinux_create_file_clear();
if (IN_SET(r, -EEXIST, -ENOTEMPTY)) {
r = rm_rf(i->path, REMOVE_ROOT|REMOVE_PHYSICAL);
if (r < 0)
return log_error_errno(r, "rm -fr %s failed: %m", i->path);
mac_selinux_create_file_prepare(i->path, S_IFLNK);
r = symlink(resolved, i->path) < 0 ? -errno : 0;
mac_selinux_create_file_clear();
}
if (r < 0) if (r < 0)
return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path); return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path);