The following commit has been merged in the master branch:
commit 9f7f2a958321d41725c0ae7f46c434fe4cbf3c6a
Author: Guillem Jover <[email protected]>
Date:   Fri Feb 25 00:21:46 2011 +0100

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

diff --git a/src/Makefile.am b/src/Makefile.am
index 8c0e804..cdba382 100644
--- a/src/Makefile.am
+++ b/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 \
diff --git a/src/depcon.c b/src/depcon.c
index 4c87fe6..1baa2d7 100644
--- a/src/depcon.c
+++ b/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
diff --git a/lib/dpkg/cleanup.c b/src/infodb.c
similarity index 57%
copy from lib/dpkg/cleanup.c
copy to src/infodb.c
index 98bf100..9a4fa50 100644
--- a/lib/dpkg/cleanup.c
+++ b/src/infodb.c
@@ -1,8 +1,9 @@
 /*
- * libdpkg - Debian packaging suite library routines
- * cleanup.c - cleanup functions, used when we need to unwind
+ * dpkg - main program for package management
+ * infodb.c - package control information database
  *
  * Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,41 +22,29 @@
 #include <config.h>
 #include <compat.h>
 
-#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <errno.h>
 #include <unistd.h>
-#include <stdio.h>
 
+#include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
+#include <dpkg/dpkg-db.h>
 
-void
-cu_closepipe(int argc, void **argv)
-{
-       int *p1 = (int *)argv[0];
-
-       close(p1[0]);
-       close(p1[1]);
-}
+#include "infodb.h"
 
-void
-cu_closefile(int argc, void **argv)
+bool
+pkg_infodb_has_file(struct pkginfo *pkg, const char *name)
 {
-       FILE *f = (FILE *)(argv[0]);
-
-       fclose(f);
-}
-
-void
-cu_closedir(int argc, void **argv)
-{
-       DIR *d = (DIR *)(argv[0]);
-
-       closedir(d);
-}
-
-void
-cu_closefd(int argc, void **argv)
-{
-       int ip = *(int *)argv[0];
-
-       close(ip);
+       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);
 }
diff --git a/lib/dpkg/pkg-show.h b/src/infodb.h
similarity index 69%
copy from lib/dpkg/pkg-show.h
copy to src/infodb.h
index 6816e39..0f211d8 100644
--- a/lib/dpkg/pkg-show.h
+++ b/src/infodb.h
@@ -1,8 +1,8 @@
 /*
  * dpkg - main program for package management
- * pkg-show.h - primitives for pkg information display
+ * infodb.h - package control information database
  *
- * Copyright © 2010 Guillem Jover <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,16 +18,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DPKG_PKG_SHOW_H
-#define DPKG_PKG_SHOW_H
+#ifndef DPKG_INFODB_H
+#define DPKG_INFODB_H
 
-#include <dpkg/macros.h>
-#include <dpkg/dpkg-db.h>
-
-DPKG_BEGIN_DECLS
+#include <stdbool.h>
 
-const char *pkg_summary(const struct pkginfo *pkg, int *len_ret);
+#include <dpkg/dpkg-db.h>
 
-DPKG_END_DECLS
+bool pkg_infodb_has_file(struct pkginfo *pkg, const char *name);
 
-#endif /* DPKG_PKG_SHOW_H */
+#endif /* DPKG_INFODB_H */
diff --git a/src/remove.c b/src/remove.c
index 9722367..00dedad 100644
--- a/src/remove.c
+++ b/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);
 

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to