Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
dcfb989852
2 mainītis faili ar 10 papildinājumiem un 7 dzēšanām
  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
   * 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.
     the conffile from the new package does not differ from the previous one.
     Thanks to Henning Makholm <henning@makholm.net>. Closes: #102609
     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 ]
   [ Updated programs translations ]
   * Catalan (Guillem Jover).
   * Catalan (Guillem Jover).

+ 6 - 7
src/divertcmd.c

@@ -162,6 +162,12 @@ check_rename(struct file *src, struct file *dst)
 	int tmpfd;
 	int tmpfd;
 
 
 	file_stat(src);
 	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);
 	file_stat(dst);
 
 
 	/*
 	/*
@@ -179,13 +185,6 @@ check_rename(struct file *src, struct file *dst)
 	if (tmpfd >= 0) {
 	if (tmpfd >= 0) {
 		close(tmpfd);
 		close(tmpfd);
 		unlink(tmpname.buf);
 		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
 	} else
 		ohshite(_("error checking '%s'"), src->name);
 		ohshite(_("error checking '%s'"), src->name);