]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: enable: overwrite broken alias symlinks
authorMike Yuan <me@yhndnzj.com>
Thu, 29 Dec 2022 06:51:06 +0000 (14:51 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 5 Jan 2023 01:10:42 +0000 (02:10 +0100)
When switching to an alternative alias provider,
the previous one might have been uninstalled or so.
It should be fine for us to overwrite them directly.

Closes #23694

src/shared/install.c

index db150247fc94bf2be59a96f9f6e8339492ed3d5f..dc6e12fd06ffacd9f6889d30a23acfc60794945c 100644 (file)
@@ -1892,6 +1892,7 @@ static int install_info_symlink_alias(
 
         STRV_FOREACH(s, info->aliases) {
                 _cleanup_free_ char *alias_path = NULL, *dst = NULL, *dst_updated = NULL;
+                bool broken;
 
                 q = install_name_printf(scope, info, *s, &dst);
                 if (q < 0) {
@@ -1912,7 +1913,14 @@ static int install_info_symlink_alias(
                 if (!alias_path)
                         return -ENOMEM;
 
-                q = create_symlink(lp, info->path, alias_path, force, changes, n_changes);
+                q = chase_symlinks(alias_path, lp->root_dir, CHASE_NONEXISTENT, NULL, NULL);
+                if (q < 0 && q != -ENOENT) {
+                        r = r < 0 ? r : q;
+                        continue;
+                }
+                broken = q == 0; /* symlink target does not exist? */
+
+                q = create_symlink(lp, info->path, alias_path, force || broken, changes, n_changes);
                 r = r < 0 ? r : q;
         }