summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2012-05-04 05:30:08 +0200
committerAllan McRae <allan@archlinux.org>2012-12-14 04:45:12 +0100
commitcfd9f1cc6948bc99d48e968efa4dd57f3375b93c (patch)
tree4b9dfa99e5f6f429ba0c60336d7d24f61d743f01
parent18ddf90ff41a9de6611400065b18f6de8dc35b01 (diff)
downloadpacman-cfd9f1cc6948bc99d48e968efa4dd57f3375b93c.tar.gz
pacman-cfd9f1cc6948bc99d48e968efa4dd57f3375b93c.tar.xz
Separate checking a files existence into a function
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--src/pacman/check.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/pacman/check.c b/src/pacman/check.c
index e3b68a59..eec12c33 100644
--- a/src/pacman/check.c
+++ b/src/pacman/check.c
@@ -26,13 +26,30 @@
#include "conf.h"
#include "util.h"
+static int check_file_exists(const char *pkgname, const char * filepath,
+ struct stat * st)
+{
+ /* use lstat to prevent errors from symlinks */
+ if(lstat(filepath, st) != 0) {
+ if(config->quiet) {
+ printf("%s %s\n", pkgname, filepath);
+ } else {
+ pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n",
+ pkgname, filepath, strerror(errno));
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
/* 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];
+ char filepath[PATH_MAX];
alpm_filelist_t *filelist;
size_t i;
@@ -43,7 +60,7 @@ int check(alpm_pkg_t *pkg)
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
return 1;
}
- strcpy(f, root);
+ strcpy(filepath, root);
pkgname = alpm_pkg_get_name(pkg);
filelist = alpm_pkg_get_files(pkg);
@@ -56,17 +73,9 @@ int check(alpm_pkg_t *pkg)
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++;
- }
+ strcpy(filepath + rootlen, path);
+
+ errors += check_file_exists(pkgname, filepath, &st);
}
if(!config->quiet) {