Kaynağa Gözat

dpkg: Refactor infodb file existence check into new pkg_infodb_has_file()

Guillem Jover 15 yıl önce
ebeveyn
işleme
9f7f2a9583
5 değiştirilmiş dosya ile 86 ekleme ve 23 silme
  1. 1 0
      src/Makefile.am
  2. 3 7
      src/depcon.c
  3. 50 0
      src/infodb.c
  4. 30 0
      src/infodb.h
  5. 2 16
      src/remove.c

+ 1 - 0
src/Makefile.am

@@ -34,6 +34,7 @@ dpkg_SOURCES = \
 	errors.c \
 	filesdb.c filesdb.h \
 	filters.c filters.h \
+	infodb.c infodb.h \
 	divertdb.c \
 	statdb.c \
 	help.c \

+ 3 - 7
src/depcon.c

@@ -32,6 +32,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 
+#include "infodb.h"
 #include "main.h"
 
 struct cyclesofarlink {
@@ -48,8 +49,6 @@ foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
                  struct pkginfo *dependedon, struct deppossi *possi)
 {
   struct cyclesofarlink *sol;
-  const char *postinstfilename;
-  struct stat stab;
 
   if(!possi)
     return false;
@@ -75,11 +74,8 @@ foundcyclebroken(struct cyclesofarlink *thislink, struct cyclesofarlink *sofar,
    * able to do something straight away when findbreakcycle returns. */
   sofar= thislink;
   for (sol = sofar; !(sol != sofar && sol->pkg == dependedon); sol = sol->prev) {
-    postinstfilename= pkgadminfile(sol->pkg,POSTINSTFILE);
-    if (lstat(postinstfilename,&stab)) {
-      if (errno == ENOENT) break;
-      ohshite(_("unable to check for existence of `%.250s'"),postinstfilename);
-    }
+    if (!pkg_infodb_has_file(sol->pkg, POSTINSTFILE))
+      break;
   }
 
   /* Now we have either a package with no postinst, or the other

+ 50 - 0
src/infodb.c

@@ -0,0 +1,50 @@
+/*
+ * dpkg - main program for package management
+ * infodb.c - package control information database
+ *
+ * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2011 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <dpkg/i18n.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/dpkg-db.h>
+
+#include "infodb.h"
+
+bool
+pkg_infodb_has_file(struct pkginfo *pkg, const char *name)
+{
+	const char *filename;
+	struct stat stab;
+
+	filename = pkgadminfile(pkg, name);
+	if (lstat(filename, &stab) == 0)
+		return true;
+	else if (errno == ENOENT)
+		return false;
+	else
+		ohshite(_("unable to check existence of `%.250s'"), filename);
+}

+ 30 - 0
src/infodb.h

@@ -0,0 +1,30 @@
+/*
+ * dpkg - main program for package management
+ * infodb.h - package control information database
+ *
+ * Copyright © 2011 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DPKG_INFODB_H
+#define DPKG_INFODB_H
+
+#include <stdbool.h>
+
+#include <dpkg/dpkg-db.h>
+
+bool pkg_infodb_has_file(struct pkginfo *pkg, const char *name);
+
+#endif /* DPKG_INFODB_H */

+ 2 - 16
src/remove.c

@@ -40,6 +40,7 @@
 #include <dpkg/myopt.h>
 #include <dpkg/triglib.h>
 
+#include "infodb.h"
 #include "filesdb.h"
 #include "main.h"
 
@@ -511,21 +512,6 @@ static void removal_bulk_remove_configfiles(struct pkginfo *pkg) {
                                 "purge", NULL);
 }
 
-static bool
-pkg_has_postrm_script(struct pkginfo *pkg)
-{
-  const char *postrmfilename;
-  struct stat stab;
-
-  postrmfilename = pkgadminfile(pkg, POSTRMFILE);
-  if (!lstat(postrmfilename, &stab))
-    return true;
-  else if (errno == ENOENT)
-    return false;
-  else
-    ohshite(_("unable to check existence of `%.250s'"), postrmfilename);
-}
-
 /*
  * This is used both by deferred_remove() in this file, and at the end of
  * process_archive() in archives.c if it needs to finish removing a
@@ -540,7 +526,7 @@ void removal_bulk(struct pkginfo *pkg) {
     removal_bulk_remove_files(pkg);
   }
 
-  foundpostrm = pkg_has_postrm_script(pkg);
+  foundpostrm = pkg_infodb_has_file(pkg, POSTRMFILE);
 
   debug(dbg_general, "removal_bulk purging? foundpostrm=%d",foundpostrm);