summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2012-05-04 12:07:50 +1000
committerAllan McRae <allan@archlinux.org>2012-12-14 13:45:12 +1000
commit18ddf90ff41a9de6611400065b18f6de8dc35b01 (patch)
treec51ae8a6ba27140ac876b1ba67ca01f621c202db
parent097d5a478b32aece93013580fdb06cacbaf0e9a0 (diff)
downloadpacman-18ddf90ff41a9de6611400065b18f6de8dc35b01.tar.xz
Move check function into its own file
There is going to be a lot of overlap in the code for the quick and full checks that can be abstracted into their own functions. Also many other file checking functions will be needed for the full check. Put all these in a separate source file. Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--src/pacman/Makefile.am1
-rw-r--r--src/pacman/check.c82
-rw-r--r--src/pacman/check.h29
-rw-r--r--src/pacman/query.c56
4 files changed, 113 insertions, 55 deletions
diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am
index d296d485..311f7c5b 100644
--- a/src/pacman/Makefile.am
+++ b/src/pacman/Makefile.am
@@ -27,6 +27,7 @@ AM_CPPFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
pacman_SOURCES = \
+ check.h check.c \
conf.h conf.c \
database.c \
deptest.c \
diff --git a/src/pacman/check.c b/src/pacman/check.c
new file mode 100644
index 00000000..e3b68a59
--- /dev/null
+++ b/src/pacman/check.c
@@ -0,0 +1,82 @@
+/*
+ * check.c
+ *
+ * Copyright (c) 2012 Pacman Development Team <pacman-dev@archlinux.org>
+ *
+ * This program 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 program 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 <limits.h>
+#include <string.h>
+#include <errno.h>
+
+/* pacman */
+#include "check.h"
+#include "conf.h"
+#include "util.h"
+
+/* Loop through the files of the package to check if they exist. */
+int check(alpm_pkg_t *pkg)
+{
+ const char *root, *pkgname;
+ size_t errors = 0;
+ size_t rootlen;
+ char f[PATH_MAX];
+ alpm_filelist_t *filelist;
+ size_t i;
+
+ root = alpm_option_get_root(config->handle);
+ rootlen = strlen(root);
+ if(rootlen + 1 > PATH_MAX) {
+ /* we are in trouble here */
+ pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
+ return 1;
+ }
+ strcpy(f, root);
+
+ pkgname = alpm_pkg_get_name(pkg);
+ filelist = alpm_pkg_get_files(pkg);
+ for(i = 0; i < filelist->count; i++) {
+ const alpm_file_t *file = filelist->files + i;
+ struct stat st;
+ const char *path = file->name;
+
+ if(rootlen + 1 + strlen(path) > PATH_MAX) {
+ pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path);
+ continue;
+ }
+ strcpy(f + rootlen, path);
+ /* use lstat to prevent errors from symlinks */
+ if(lstat(f, &st) != 0) {
+ if(config->quiet) {
+ printf("%s %s\n", pkgname, f);
+ } else {
+ pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n",
+ pkgname, f, strerror(errno));
+ }
+ errors++;
+ }
+ }
+
+ if(!config->quiet) {
+ printf(_n("%s: %jd total file, ", "%s: %jd total files, ",
+ (unsigned long)filelist->count), pkgname, (intmax_t)filelist->count);
+ printf(_n("%jd missing file\n", "%jd missing files\n",
+ (unsigned long)errors), (intmax_t)errors);
+ }
+
+ return (errors != 0 ? 1 : 0);
+}
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/check.h b/src/pacman/check.h
new file mode 100644
index 00000000..b107a7f5
--- /dev/null
+++ b/src/pacman/check.h
@@ -0,0 +1,29 @@
+/*
+ * check.h
+ *
+ * Copyright (c) 2012 Pacman Development Team <pacman-dev@archlinux.org>
+ *
+ * This program 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 program 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 _PM_CHECK_H
+#define _PM_CHECK_H
+
+#include <alpm.h>
+
+int check(alpm_pkg_t *pkg);
+
+#endif /* _PM_CHECK_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 72891200..f2d5f007 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
-#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
@@ -33,6 +32,7 @@
/* pacman */
#include "pacman.h"
#include "package.h"
+#include "check.h"
#include "conf.h"
#include "util.h"
@@ -393,60 +393,6 @@ static int filter(alpm_pkg_t *pkg)
return 1;
}
-/* Loop through the packages. For each package,
- * loop through files to check if they exist. */
-static int check(alpm_pkg_t *pkg)
-{
- const char *root, *pkgname;
- size_t errors = 0;
- size_t rootlen;
- char f[PATH_MAX];
- alpm_filelist_t *filelist;
- size_t i;
-
- root = alpm_option_get_root(config->handle);
- rootlen = strlen(root);
- if(rootlen + 1 > PATH_MAX) {
- /* we are in trouble here */
- pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
- return 1;
- }
- strcpy(f, root);
-
- pkgname = alpm_pkg_get_name(pkg);
- filelist = alpm_pkg_get_files(pkg);
- for(i = 0; i < filelist->count; i++) {
- const alpm_file_t *file = filelist->files + i;
- struct stat st;
- const char *path = file->name;
-
- if(rootlen + 1 + strlen(path) > PATH_MAX) {
- pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path);
- continue;
- }
- strcpy(f + rootlen, path);
- /* use lstat to prevent errors from symlinks */
- if(lstat(f, &st) != 0) {
- if(config->quiet) {
- printf("%s %s\n", pkgname, f);
- } else {
- pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n",
- pkgname, f, strerror(errno));
- }
- errors++;
- }
- }
-
- if(!config->quiet) {
- printf(_n("%s: %jd total file, ", "%s: %jd total files, ",
- (unsigned long)filelist->count), pkgname, (intmax_t)filelist->count);
- printf(_n("%jd missing file\n", "%jd missing files\n",
- (unsigned long)errors), (intmax_t)errors);
- }
-
- return (errors != 0 ? 1 : 0);
-}
-
static int display(alpm_pkg_t *pkg)
{
int ret = 0;