summaryrefslogtreecommitdiff
path: root/src/infodb.c
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2011-02-25 00:21:46 +0100
committerGuillem Jover <guillem@debian.org>2011-03-02 07:35:00 +0100
commit9f7f2a958321d41725c0ae7f46c434fe4cbf3c6a (patch)
tree0528d3ddb0ae6d070dbe8f847288e05ddd057732 /src/infodb.c
parentae3500585ce59833e7b3094e1615fa273d7b8527 (diff)
downloaddpkg-9f7f2a958321d41725c0ae7f46c434fe4cbf3c6a.tar.gz
dpkg: Refactor infodb file existence check into new pkg_infodb_has_file()
Diffstat (limited to 'src/infodb.c')
-rw-r--r--src/infodb.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/infodb.c b/src/infodb.c
new file mode 100644
index 000000000..9a4fa50d3
--- /dev/null
+++ b/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);
+}