This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=fe088a3e855fbf17c70d0ffd939eefe81a9685f7

commit fe088a3e855fbf17c70d0ffd939eefe81a9685f7
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Mon Feb 7 00:29:35 2022 +0100

    u-a: Move symlink removal inside fsys_symlink()
    
    To be able to create the symlink, we need to first remove it. Do this
    within the function, which reduces the amount of work, as then we only
    need to compute the root pathname one time.
    
    Changelog: internal
---
 utils/update-alternatives.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 2029b2bb2..53364d3ba 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -638,6 +638,9 @@ fsys_symlink(const char *filename, const char *linkname)
 
        root_linkname = fsys_get_path(linkname);
 
+       if (unlink(root_linkname) < 0 && errno != ENOENT)
+               syserr(_("unable to remove '%s'"), root_linkname);
+
        if (symlink(filename, root_linkname))
                syserr(_("error creating symbolic link '%.255s'"), 
root_linkname);
 
@@ -1979,7 +1982,6 @@ alternative_prepare_install_single(struct alternative *a, 
const char *name,
        /* Create link in /etc/alternatives. */
        fntmp = xasprintf("%s/%s" ALT_TMP_EXT, altdir, name);
        fn = xasprintf("%s/%s", altdir, name);
-       fsys_rm(fntmp);
        fsys_symlink(file, fntmp);
        alternative_add_commit_op(a, OPCODE_MV, fntmp, fn);
        free(fntmp);
@@ -1987,7 +1989,6 @@ alternative_prepare_install_single(struct alternative *a, 
const char *name,
        if (alternative_path_needs_update(linkname, fn)) {
                /* Create alternative link. */
                fntmp = xasprintf("%s" ALT_TMP_EXT, linkname);
-               fsys_rm(fntmp);
                fsys_symlink(fn, fntmp);
                alternative_add_commit_op(a, OPCODE_MV, fntmp, linkname);
                free(fntmp);

-- 
Dpkg.Org's dpkg

Reply via email to