Hi! On Fri, 2011-08-26 at 08:44:13 +0200, Salvatore Bonaccorso wrote: > But attached is an updated version for the patch, is this better > suitable so far? Jan, changed the parts you mentioned.
The other day while I was messing with u-a I prepared the attached patch which I think is better (but actually pretty close to what you have now here :). But forgot including it in my push. In any case I'll include it for my next one. thanks, guillem
>From db7c96a14d78bf7ee5a6a89c1be39880cb288c5e Mon Sep 17 00:00:00 2001 From: Guillem Jover <guil...@debian.org> Date: Fri, 19 Aug 2011 18:07:13 +0200 Subject: [PATCH] u-a: Update alternative links only if they change There's no point in changing the links to the same target. This also helps when systems might have a read-only file system mounted, but a writable database. Closes: #636700 Based-on-patch-by: Salvatore Bonaccorso <car...@debian.org> Signed-off-by: Guillem Jover <guil...@debian.org> --- utils/update-alternatives.c | 25 ++++++++++++++++++++++--- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index 8e82bb6..9b4e2a4 100644 --- a/utils/update-alternatives.c +++ b/utils/update-alternatives.c @@ -1651,6 +1651,25 @@ alternative_can_replace_path(const char *linkname) return replace_link; } +static bool +alternative_path_needs_update(const char *linkname, const char *filename) +{ + char *linktarget; + bool update; + + if (opt_force) + return true; + + linktarget = xreadlink(linkname, false); + if (strcmp(linktarget, filename) == 0) + update = false; + else + update = true; + free(linktarget); + + return update; +} + static void alternative_prepare_install_single(struct alternative *a, const char *name, const char *linkname, const char *file) @@ -1665,15 +1684,15 @@ alternative_prepare_install_single(struct alternative *a, const char *name, alternative_add_commit_op(a, opcode_mv, fntmp, fn); free(fntmp); - if (alternative_can_replace_path(linkname)) { + if (!alternative_can_replace_path(linkname)) { + warning(_("not replacing %s with a link."), linkname); + } else if (alternative_path_needs_update(linkname, fn)) { /* Create alternative link. */ xasprintf(&fntmp, "%s" DPKG_TMP_EXT, linkname); checked_rm(fntmp); checked_symlink(fn, fntmp); alternative_add_commit_op(a, opcode_mv, fntmp, linkname); free(fntmp); - } else { - warning(_("not replacing %s with a link."), linkname); } free(fn); } -- 1.7.5.4