<term><varname>L</varname></term>
<term><varname>L+</varname></term>
<listitem><para>Create a symlink if it does not exist
- yet. If suffixed with <varname>+</varname> and a file
- already exists where the symlink is to be created, it will
- be removed and be replaced by the symlink. If the argument
- is omitted, symlinks to files with the same name residing in
- the directory <filename>/usr/share/factory/</filename> are
- created. Note that permissions and ownership on symlinks
- are ignored.</para></listitem>
+ yet. If suffixed with <varname>+</varname> and a file or
+ directory already exists where the symlink is to be created,
+ it will be removed and be replaced by the symlink. If the
+ argument is omitted, symlinks to files with the same name
+ residing in the directory
+ <filename>/usr/share/factory/</filename> are created. Note
+ that permissions and ownership on symlinks are ignored.
+ </para></listitem>
</varlistentry>
<varlistentry>
r = symlink_atomic(resolved, i->path);
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)
return log_error_errno(r, "symlink(%s, %s) failed: %m", resolved, i->path);