tag 636700 + patch
thanks

Hi dpkg Team!

On Fri, Aug 05, 2011 at 02:18:58PM +0200, Salvatore Bonaccorso wrote:
> Indeed in the above setup, /usr/lib/nvidia does not have to be
> touched, as it is already correctly pointing to
> /etc/alternatives/nvidia. It would thus be nice, to not update
> symlinks in this case, when they are already correct.

Attached is a tentative patch trying to solve this: a link should only
be updated, if it does not point to the right place.

Is this correct, and if you agree, could it be applied?

Regards
Salvatore
From 9752cd68b05a7dde92e549585a50cf85e166681e Mon Sep 17 00:00:00 2001
From: Jan Hacker <hack...@ee.ethz.ch>
Date: Tue, 16 Aug 2011 11:33:07 +0200
Subject: [PATCH] update-alternatives: Update a symlink only if the update is needed.

update-alternatives: Update a symlink only if the update is needed. If
the symlink is already correct don't try to update the link.
---
 utils/update-alternatives.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index d829a16..f858c84 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -1645,7 +1645,9 @@ static void
 alternative_prepare_install_single(struct alternative *a, const char *name,
 				   const char *linkname, const char *file)
 {
-	char *fntmp, *fn;
+	char *fntmp, *fn, *lntarget;
+	bool alternative_needs_update = true;
+	struct stat st;
 
 	/* Create link in /etc/alternatives. */
 	xasprintf(&fntmp, "%s/%s" DPKG_TMP_EXT, altdir, name);
@@ -1655,7 +1657,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)) {
+	/* determine if alternative_needs_update, i.e. link already points to correct target */
+	if (lstat(linkname, &st) != -1) {
+		lntarget = xreadlink(linkname,false);
+		if (S_ISLNK(st.st_mode)  && strcmp(fn, lntarget) == 0) {
+			alternative_needs_update = false;	
+		}
+	}
+
+	if (alternative_can_replace_path(linkname) && alternative_needs_update) {
 		/* Create alternative link. */
 		xasprintf(&fntmp, "%s" DPKG_TMP_EXT, linkname);
 		checked_rm(fntmp);
-- 
1.7.2.5

Attachment: signature.asc
Description: Digital signature

Reply via email to