Просмотр исходного кода

dpkg: Do not fail when trying to remove the root directory

This will happen when removing the last package from an installation,
which does never happen on normal conditions on Debian-based systems.
But it can happen either on other distributions where dpkg is a foreign
package manager, or on test databases.
Guillem Jover лет назад: 15
Родитель
Сommit
626560b311
2 измененных файлов с 13 добавлено и 0 удалено
  1. 3 0
      debian/changelog
  2. 10 0
      src/remove.c

+ 3 - 0
debian/changelog

@@ -22,6 +22,9 @@ dpkg (1.16.0) UNRELEASED; urgency=low
     Closes: #31141
   * Propagate --admindir to programs run from maintainer scritpts.
     Closes: #97076
+  * Do not fail when trying to remove the root directory. This will only
+    happen either on distributions where dpkg is a foreign package manager,
+    or on artificial dpkg databases.
 
   [ Raphaël Hertzog ]
   * Fail properly when debian/source/format is empty. Closes: #600854

+ 10 - 0
src/remove.c

@@ -259,6 +259,11 @@ static void removal_bulk_remove_files(
                 pkg->name, namenode->name, strerror(errno));
         push_leftover(&leftover,namenode);
         continue;
+      } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
+        debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
+              fnvb.buf);
+        push_leftover(&leftover, namenode);
+        continue;
       }
       if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);
       debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);
@@ -368,6 +373,11 @@ static void removal_bulk_remove_leftover_dirs(struct pkginfo *pkg) {
               pkg->name, namenode->name, strerror(errno));
       push_leftover(&leftover,namenode);
       continue;
+    } else if (errno == EINVAL && strcmp(usenode->name, "/.") == 0) {
+      debug(dbg_eachfiledetail, "removal_bulk '%s' root directory, cannot remove",
+            fnvb.buf);
+      push_leftover(&leftover, namenode);
+      continue;
     }
     if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);