Browse Source

dpkg-divert: Do not rename files owned by the diverting package

If the file is already owned by the package diverting it, that will
actually mess up the filesystem for no good reason, just ignore the
request and issue a message stating so.

Closes: #588077
Guillem Jover 14 years ago
parent
commit
148ed36543
2 changed files with 36 additions and 1 deletions
  1. 2 0
      debian/changelog
  2. 34 1
      src/divertcmd.c

+ 2 - 0
debian/changelog

@@ -31,6 +31,8 @@ dpkg (1.16.3) UNRELEASED; urgency=low
   * Add x32 support to abitable, ostable and triplettable. Closes: #667037
   * Fix start-stop-daemon to work with relative --exec arguments and --chdir.
     Closes: #669047
+  * Ignore request to rename a file owned by the diverting package on
+    «dpkg-divert --add --rename». Closes: #588077
 
   [ Helge Kreutzmann ]
   * Fix a typo in man/dpkg-buildflags.1.

+ 34 - 1
src/divertcmd.c

@@ -3,7 +3,7 @@
  *
  * Copyright © 1995 Ian Jackson
  * Copyright © 2000, 2001 Wichert Akkerman
- * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ * Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
  *
@@ -382,6 +382,31 @@ divertdb_write(void)
 	free(dbname);
 }
 
+static bool
+diversion_is_owned_by_self(struct pkgset *set, struct filenamenode *namenode)
+{
+	struct pkginfo *pkg;
+	struct filepackages_iterator *iter;
+	bool owned = false;
+
+	if (set == NULL)
+		return false;
+
+	for (pkg = &set->pkg; pkg; pkg = pkg->arch_next)
+		ensure_packagefiles_available(pkg);
+
+	iter = filepackages_iter_new(namenode);
+	while ((pkg = filepackages_iter_next(iter))) {
+		if (pkg->set == set) {
+			owned = true;
+			break;
+		}
+	}
+	filepackages_iter_free(iter);
+
+	return owned;
+}
+
 static int
 diversion_add(const char *const *argv)
 {
@@ -468,6 +493,14 @@ diversion_add(const char *const *argv)
 		printf(_("Adding '%s'\n"), diversion_describe(contest));
 	if (opt_rename)
 		opt_rename = check_rename(&file_from, &file_to);
+	/* Check we are not renaming a file owned by the diverting pkgset. */
+	if (opt_rename && diversion_is_owned_by_self(pkgset, fnn_from)) {
+		if (opt_verbose > 0)
+			printf(_("Ignoring request to rename file '%s' "
+			         "owned by diverting package '%s'\n"),
+			       filename, pkgset->name);
+		opt_rename = false;
+	}
 	if (!opt_test) {
 		divertdb_write();
 		if (opt_rename)