Ver código fonte

dpkg-divert: Disable renaming of the source file does not exist

This makes it consistent with the general dpkg behaviour of honouring
file removals by the administrator.

Closes: #550252

As a side effect, this avoids useless errors when the destination
directory is not existent or writable.

Closes: #581544
Guillem Jover 16 anos atrás
pai
commit
dcfb989852
2 arquivos alterados com 10 adições e 7 exclusões
  1. 4 0
      debian/changelog
  2. 6 7
      src/divertcmd.c

+ 4 - 0
debian/changelog

@@ -74,6 +74,10 @@ dpkg (1.15.8) UNRELEASED; urgency=low
   * Add new dpkg --force-confask option that forces a conffile prompt when
     the conffile from the new package does not differ from the previous one.
     Thanks to Henning Makholm <henning@makholm.net>. Closes: #102609
+  * On dpkg-divert --rename, check if the source file exists, and disable
+    renaming if it does not. Closes: #550252
+    As a side effect, this avoids useless errors when the destination
+    directory is not existent or writable. Closes: #581544
 
   [ Updated programs translations ]
   * Catalan (Guillem Jover).

+ 6 - 7
src/divertcmd.c

@@ -162,6 +162,12 @@ check_rename(struct file *src, struct file *dst)
 	int tmpfd;
 
 	file_stat(src);
+
+	/* If the source file is not present and we are not going to do
+	 * the rename anyway there's no point in checking any further. */
+	if (src->stat_state == file_stat_nofile)
+		return false;
+
 	file_stat(dst);
 
 	/*
@@ -179,13 +185,6 @@ check_rename(struct file *src, struct file *dst)
 	if (tmpfd >= 0) {
 		close(tmpfd);
 		unlink(tmpname.buf);
-	} else if (errno == ENOENT) {
-		varbuf_destroy(&tmpname);
-
-		/* If the source file is not present and we are not going
-		 * to do the rename anyway there's no point in checking the
-		 * target. */
-		return false;
 	} else
 		ohshite(_("error checking '%s'"), src->name);