Преглед на файлове

dpkg: Do not fail when removing non-existent files on read-only filesystems

Trying to rmdir(2) or unlink(2) a non-existent pathname on at least
Linux returns with EROFS. Handle this case specifically to check if
the pathname exists with access(2).

Closes: #838877
Guillem Jover преди 9 години
родител
ревизия
4daaec6bb8
променени са 2 файла, в които са добавени 9 реда и са изтрити 0 реда
  1. 2 0
      debian/changelog
  2. 7 0
      lib/dpkg/path-remove.c

+ 2 - 0
debian/changelog

@@ -67,6 +67,8 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
     - Hook it into the dpkg-buildpackage machinery.
     Based on a patch by Jérémy Bobbio <lunar@debian.org>. Closes: #138409
   * Enable dpkg-buildpackage -Jauto by default. Closes: #842845
+  * Fix dpkg to not fail when removing non-existent backup files on read-only
+    filesystems. Closes: #838877
   * Architecture support:
     - Add support for AIX operating system.
     - Add a version pseudo-field to the arch tables.

+ 7 - 0
lib/dpkg/path-remove.c

@@ -137,6 +137,13 @@ path_remove_tree(const char *pathname)
 		if (errno == ENOTDIR)
 			return;
 	}
+	/* Trying to remove a directory or a file on a read-only filesystem,
+	 * even if non-existent, always returns EROFS. */
+	if (errno == EROFS) {
+		if (access(pathname, F_OK) < 0 && errno == ENOENT)
+			return;
+		errno = EROFS;
+	}
 	if (errno != ENOTEMPTY && errno != EEXIST) /* Huh? */
 		ohshite(_("unable to securely remove '%.255s'"), pathname);