[Fpkg-cvs] CVS: freepkg/lib depend.c entry.c filedb.c lib.h list.h manager.c match.c package.c which
Status: Alpha
Brought to you by:
jlea
From: Jeremy L. <jl...@us...> - 2004-05-03 11:42:02
|
jlea 04/05/03 04:41:56 Modified: lib depend.c entry.c filedb.c lib.h list.h manager.c match.c package.c which.c Log: Get in-place upgrading working. Remove support for @options extract-in-place, and other minor cleanups. Revision Changes Path 1.5 +3 -4 freepkg/lib/depend.c Index: depend.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/depend.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- depend.c 30 Apr 2004 12:48:49 -0000 1.4 +++ depend.c 3 May 2004 11:41:55 -0000 1.5 @@ -181,7 +181,7 @@ */ PLIST_FOREACH(w, &wl) { if (scan_which_entry(w) == NULL) { - verify_which(&wl); + verify_filedb(); break; } } @@ -274,15 +274,14 @@ error_code delete_name_entry(name_list *nl, const char *pkg) { - name_entry *n, *tmp = NULL; + name_entry *n, *tmp; if (nl == NULL || NULLSTR(pkg)) return FAIL; - PLIST_FOREACH(n, nl) { + PLIST_REMEACH(n, nl, tmp) { if (strcmp(n->name, pkg) == 0) { PLIST_REMOVE(nl, n, tmp); free(n); - n = tmp; } } return SUCCESS; 1.4 +57 -54 freepkg/lib/entry.c Index: entry.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/entry.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- entry.c 30 Apr 2004 09:53:18 -0000 1.3 +++ entry.c 3 May 2004 11:41:55 -0000 1.4 @@ -102,11 +102,16 @@ * Never leave a dangling dbdir, but don't commit any outstanding * changes. */ - if (pe->status != PKG_REGISTERED && pe->status != PKG_CHANGED) { + if (pe->status < PKG_REGISTERED) { remove_dir(pe->dbdir); pe->dbdir[0] = '\0'; pe->status = PKG_UNKNOWN; } + if (pe->status > PKG_REGISTERED && isdir(pe->dbdir)) { + msg_warn("Ooops, leaving package database in a mess!"); + pe->dbdir[0] = '\0'; + pe->status = PKG_UNKNOWN; + } } /* @@ -350,7 +355,9 @@ return FAIL; break; + case PKG_UPGRADE: case PKG_DELETE: + case PKG_DELETED: msg_error(2, "package entry cannot be scaned during delete"); return FAIL; } @@ -389,7 +396,7 @@ * Extract a package, if it's not already extracted. */ error_code -extract_pkg_entry(pkg_entry *pe, boolean inplace) +extract_pkg_entry(pkg_entry *pe) { plist_entry *p; @@ -412,37 +419,11 @@ /* It's already been extracted */ if (pe->status > PKG_SPECIAL) return SUCCESS; - /* Extract directly rather than moving? Oh goodie! */ - if (inplace) { - msg_verbose("Doing in-place extraction for %s\n", pe->url); - if ((p = find_plist_entry(&pe->pkg->plist, PLIST_CWD, NULL)) != NULL) { - /* If this is a direct extract and we didn't want it, stop now. */ - if (PkgMgr.fake) - return SUCCESS; - if (!isdir(p->name)) { - msg_verbose("Desired prefix of %s does not exist, creating..\n", p->name); - make_hierarchy(p->name, NULL, NULL, NULL); - if (enter_dir(p->name) == FAIL) { - warn("unable to change directory to `%s'", p->name); - return FAIL; - } - } - } else { - msg_warn("no prefix specified in `%s' - this is a bad package!", pe->url); - return FAIL; - } - /* Finally unpack the whole mess */ - if (unpack_package(pe->url, NULL)) { - msg_warn("unable to extract `%s'!", pe->url); - return FAIL; - } - } else { - if (enter_dir(pe->tmpdir) == FAIL) - return FAIL; - if (unpack_package(pe->url, NULL) == FAIL) { - msg_warn("unable to extract `%s'!", pe->url); - return FAIL; - } + if (enter_dir(pe->tmpdir) == FAIL) + return FAIL; + if (unpack_package(pe->url, NULL) == FAIL) { + msg_warn("unable to extract `%s'!", pe->url); + return FAIL; } pe->status = PKG_EXTRACTED; return SUCCESS; @@ -456,7 +437,7 @@ { char *cp; plist_entry *p; - boolean inplace; + match_list ml = { PLIST_HEAD_INITIALIZER }; if (pe == NULL) return FAIL; @@ -468,18 +449,25 @@ return SUCCESS; if (scan_pkg_entry(pe) == FAIL) return FAIL; - inplace = (pe->pkg->options & PKG_OPTION_INPLACE ? TRUE : FALSE); - if (extract_pkg_entry(pe, inplace) == FAIL) + if (extract_pkg_entry(pe) == FAIL) return FAIL; - /* See if we're already registered */ + /* See if we're already registered. XXX: (jlea) Delay for upgrade? */ if (pkg_mgr_check(pe->pkg->name) && !PkgMgr.force) { msg_warn("package `%s' already recorded as installed", pe->pkg->name); return FAIL; } - if (conflict_package(pe->pkg) == TRUE && !PkgMgr.force) + if (check_package(pe->pkg, &ml) == TRUE) { + msg_warn("Package failed pre-install checks. Failing..."); + return FAIL; + } + if (depend_package(pe->pkg, pe->url) == FAIL) { + msg_warn("Unable to install required package depends. Failing..."); return FAIL; - if (depend_package(pe->pkg, pe->url) == FAIL) + } + if (upgrade_pkg_entry(&ml, pe) == FAIL) { + msg_warn("Unable to upgrade existing packages. Failing..."); return FAIL; + } pe->status = PKG_INSTALL; if (install_package(pe->pkg) == FAIL) return FAIL; @@ -543,6 +531,7 @@ /* If something changed, we can't have a NULL pkg. */ if (pe->pkg == NULL) return FAIL; + /* Make sure we're in the right directory */ if (scan_pkg_entry(pe) == FAIL) return FAIL; if (write_package(pe->pkg) == FAIL) @@ -552,27 +541,36 @@ } /* - * Upgrade one packge entry to another. + * Upgrade all of the packages which either have the same origin or have + * conflicting files and the same pkgroot name. */ error_code -upgrade_pkg_entry(pkg_entry *from, pkg_entry *to) +upgrade_pkg_entry(match_list *ml, pkg_entry *pe) { + match_entry *m; - if (from == NULL || to == NULL) - return FAIL; - if (from->status != PKG_REGISTERED) - return FAIL; - if (scan_pkg_entry(from) == FAIL - || scan_pkg_entry(to) == FAIL) - return FAIL; - if (to->status < PKG_SPECIAL || to->status > PKG_EXTRACTED) - return FAIL; - if (upgrade_package(from->pkg, to->pkg) == FAIL) + if (ml == NULL || pe == NULL) return FAIL; - if (delete_pkg_entry(from) == FAIL) + if (pe->status < PKG_SPECIAL || pe->status > PKG_EXTRACTED) return FAIL; - if (install_pkg_entry(to) == FAIL) + if (scan_pkg_entry(pe) == FAIL) return FAIL; + while (!PLIST_EMPTY(ml)) { + PLIST_REMOVE_HEAD(ml, m); + if (m->pe->status != PKG_REGISTERED) + return FAIL; + if (scan_pkg_entry(m->pe) == FAIL) + return FAIL; + pe->status = PKG_UPGRADE; + msg_verbose("Upgrading package %s\n", m->pe->pkg->name); + if (upgrade_package(m->pe->pkg, pe->pkg) == FAIL) + return FAIL; + if (delete_pkg_entry(m->pe) == FAIL) + return FAIL; + free(m); + } + /* Hope this is right... We need to push and pop... */ + enter_dir(pe->tmpdir); return SUCCESS; } @@ -645,6 +643,7 @@ { plist_entry *p; name_entry *n; + pkg_entry *tmp = NULL; if (pe == NULL) return FAIL; @@ -685,6 +684,10 @@ return FAIL; } } + pe->status = PKG_DELETED; + cleanup_pkg_entry(pe); + PLIST_REMOVE(&PkgMgr, pe, tmp); + free(pe); return SUCCESS; } @@ -774,7 +777,7 @@ /* XXX: (jlea) This should used pkg_mgr_add_master() */ if (fetch_pkg_entry(pe) == FAIL) return FAIL; - if (extract_pkg_entry(pe, FALSE) == FAIL) + if (extract_pkg_entry(pe) == FAIL) return FAIL; pe->status = PKG_TEMP; /* We can't size packages that are not installed */ 1.2 +74 -1 freepkg/lib/filedb.c Index: filedb.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/filedb.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- filedb.c 26 Apr 2004 00:05:47 -0000 1.1 +++ filedb.c 3 May 2004 11:41:55 -0000 1.2 @@ -66,6 +66,7 @@ static const char *get_filedb(const char *); static error_code put_filedb(const char *, const char *); static error_code remove_filedb(const char *); +static error_code verify_scan(pkg_entry *); /* * Open the database. If we fail, or if requested, we try to rebuild and @@ -177,7 +178,8 @@ return NULL; while (1) { if ((cp = get_filedb(w->file)) != NULL) { - if ((pe = find_pkg_entry(cp)) != NULL) + if ((pe = find_pkg_entry(cp)) != NULL + && pe->status == PKG_REGISTERED) break; /* Stale DB! */ open_filedb(TRUE); @@ -192,6 +194,77 @@ } /* + * Check our list of files against a package's plist, to see if we have a + * match. Then check to see if the DB agrees. Blow it away if it lies... + */ +error_code +verify_scan(pkg_entry *pe) +{ + plist_entry *p; + which_entry w; + char *dir = "."; + char tmp[PATH_MAX]; + + if (pe == NULL) + return FAIL; + if (pe->status != PKG_REGISTERED) + return FAIL; + if (scan_pkg_entry(pe) == FAIL) + return FAIL; + w.type = WHICH_FILE; + PLIST_FOREACH(p, &pe->pkg->plist) { + switch(p->type) { + case PLIST_CWD: + dir = p->name; + break; + case PLIST_FILE: + if (p->ignore) + break; + snprintf(tmp, PATH_MAX, "%s/%s", dir, p->name); + if (!isfile(tmp)) + break; + realpath(tmp, w.file); + if (scan_which_entry(&w) != pe) { + if (open_filedb(TRUE) == FAIL + || (scan_which_entry(&w) != pe)) { + msg_error(2, "Failed to fix database!"); + return FAIL; + } else + return SUCCESS; + } + break; + default: + break; + } + } + return SUCCESS; +} + +/* + * Check a the DB results of a scan against the installed packages. + */ +error_code +verify_filedb() +{ + pkg_entry *pe; + char cwd[PATH_MAX]; + + if (!getcwd(cwd, PATH_MAX)) + strlcpy(cwd, PkgMgr.wrkdir, PATH_MAX); + PLIST_FOREACH(pe, &PkgMgr) { + if (pe->status == PKG_REGISTERED) { + if (verify_scan(pe) == FAIL) { + enter_dir(cwd); + return FAIL; + } + cleanup_pkg_entry(pe); + } + } + enter_dir(cwd); + return SUCCESS; +} + +/* * Store value "file" with key "pkgname" in database. We just return an * error if the key already exists. This should never happen, because we * always check first. 1.5 +6 -5 freepkg/lib/lib.h Index: lib.h =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/lib.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- lib.h 30 Apr 2004 12:48:49 -0000 1.4 +++ lib.h 3 May 2004 11:41:55 -0000 1.5 @@ -294,7 +294,9 @@ PKG_INSTALLED, /* We've installed, but it's not registered yet */ PKG_REGISTERED, /* We've got it installed */ PKG_CHANGED, /* Someone changed it's depends */ + PKG_UPGRADE, /* We're trying to upgrade it */ PKG_DELETE, /* We're trying to delete it */ + PKG_DELETED, /* We've successfully deleted it */ } pkg_status_t; /* @@ -438,14 +440,13 @@ error_code add_package_filedb(package *); error_code remove_package_filedb(package *); pkg_entry * scan_which_entry(which_entry *); +error_code verify_filedb(); /* which.c */ which_entry * new_which_entry(void); void free_which(which_list *); which_entry * add_which_entry(which_list *, enum which_t, char *); error_code add_which_plist(which_list *, char *); -error_code verify_scan(which_list *, pkg_entry *); -error_code verify_which(which_list *); /* depend.c */ depend_entry * new_depend_entry(void); @@ -514,7 +515,7 @@ error_code extract_package(package *); error_code install_package(package *); error_code register_package(package *, char *); -boolean conflict_package(package *); +boolean check_package(package *, match_list *); error_code depend_package(package *, char*); error_code undepend_package(package *); error_code delete_package(package *); @@ -531,7 +532,7 @@ error_code match_pkg_entry(match_list *, const char *); error_code match_pkg_regex(match_list *, const char *); error_code fetch_pkg_entry(pkg_entry *); -error_code extract_pkg_entry(pkg_entry *, boolean); +error_code extract_pkg_entry(pkg_entry *); error_code scan_pkg_entry(pkg_entry *); error_code install_pkg_entry(pkg_entry *); error_code register_pkg_entry(pkg_entry *); @@ -541,7 +542,7 @@ error_code delete_pkg_entry(pkg_entry *); pkg_entry * create_pkg_entry(pkg_info *, char *); error_code package_pkg_entry(pkg_entry *, char *); -error_code upgrade_pkg_entry(pkg_entry *, pkg_entry *); +error_code upgrade_pkg_entry(match_list *, pkg_entry *); error_code show_pkg_entry(pkg_entry *, unsigned int); error_code version_pkg_entry(pkg_entry *); 1.2 +7 -0 freepkg/lib/list.h Index: list.h =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/list.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- list.h 26 Apr 2004 00:05:51 -0000 1.1 +++ list.h 3 May 2004 11:41:55 -0000 1.2 @@ -58,6 +58,13 @@ (var); \ (var) = ((var) ? PLIST_NEXT((var)) : NULL)) +#define PLIST_REMEACH(var, head, tmp) \ + for ((var) = PLIST_FIRST((head)), (tmp) = NULL; \ + (var); \ + (var) = ((tmp) != NULL ? \ + (tmp) == PLIST_FIRST((head)) ? (tmp) : PLIST_NEXT((tmp)) \ + : (var) != NULL ? PLIST_NEXT((var)) : NULL), (tmp) = NULL ) + #define PLIST_INIT(head) do { \ PLIST_FIRST((head)) = NULL; \ PLIST_LAST((head)) = NULL; \ 1.4 +13 -3 freepkg/lib/manager.c Index: manager.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/manager.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- manager.c 30 Apr 2004 09:53:18 -0000 1.3 +++ manager.c 3 May 2004 11:41:55 -0000 1.4 @@ -302,7 +302,8 @@ pkg_mgr_origin(match_list *ml, const char *pkgarg) { pkg_entry *pe; - char pkgroot[PATH_MAX], pkgorig[PATH_MAX], tmp[PATH_MAX], *cp; + char pkgroot[PATH_MAX], pkgorig[PATH_MAX]; + char cwd[PATH_MAX], tmp[PATH_MAX], *cp; boolean matched = FALSE; if (ml == NULL || NULLSTR(pkgarg)) @@ -313,13 +314,21 @@ *cp = '\0'; else pkgroot[0] = '\0'; + if (NULLSTR(pkgorig)) + return FAIL; + if (!getcwd(cwd, PATH_MAX)) + strlcpy(cwd, PkgMgr.wrkdir, PATH_MAX); PLIST_FOREACH(pe, &PkgMgr) { + if (pe->status != PKG_REGISTERED) + continue; if (NULLSTR(pe->dbdir) || (!NULLSTR(pkgroot) && pkgroot_of(tmp, pe->dbdir, PATH_MAX) != NULL && strpcmp(pkgroot, tmp) != 0)) continue; - if (scan_pkg_entry(pe) == FAIL) + if (scan_pkg_entry(pe) == FAIL) { + enter_dir(cwd); return FAIL; + } if (!NULLSTR(pe->pkg->origin) && (strcmp(pe->pkg->origin, pkgorig) == 0 || fnmatch(pkgorig, pe->pkg->origin, 0) == 0)) { @@ -328,6 +337,7 @@ } cleanup_pkg_entry(pe); } + enter_dir(cwd); return (matched ? SUCCESS : FAIL); } @@ -431,7 +441,7 @@ strlcpy(pe->url, pkgarg, PATH_MAX); if (fetch_pkg_entry(pe) == FAIL) return NULL; - if (extract_pkg_entry(pe, FALSE) == FAIL) + if (extract_pkg_entry(pe) == FAIL) return NULL; pe->status = PKG_LEAVE; return copy_string(pe->tmpdir); 1.3 +1 -2 freepkg/lib/match.c Index: match.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/match.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- match.c 30 Apr 2004 09:53:18 -0000 1.2 +++ match.c 3 May 2004 11:41:55 -0000 1.3 @@ -110,11 +110,10 @@ return NULL; if ((nm = new_match_entry()) == NULL) return NULL; - PLIST_FOREACH(m, ml) { + PLIST_REMEACH(m, ml, tmp) { if (m->pe == pe) { PLIST_REMOVE(ml, m, tmp); free(m); - m = tmp; } } nm->pe = pe; 1.5 +91 -16 freepkg/lib/package.c Index: package.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/package.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- package.c 30 Apr 2004 12:48:49 -0000 1.4 +++ package.c 3 May 2004 11:41:55 -0000 1.5 @@ -860,10 +860,11 @@ } } - /* Now finally extract the entire show if we're not going direct */ - if (!(pkg->options & PKG_OPTION_INPLACE) && !PkgMgr.fake) + /* Now finally extract the entire show */ + if (!PkgMgr.fake) extract_package(pkg); + /* XXX: (jlea) Shouldn't this be before the extract? */ if (!PkgMgr.fake && isnode(MTREE_FNAME)) { msg_verbose("Running mtree for %s..\n", pkg->name); p = find_plist_entry(&pkg->plist, PLIST_CWD, NULL); @@ -941,28 +942,99 @@ } /* - * Check to see if any packages which conflict with this package are - * installed. + * Check a package before installation. This is a three stage process: + * 1. Check to see if any installed packages match the globbing patterns + * in our conlficts list. + * 2. Next we match a list of possible upgradable packages, which we will + * use later. This includes any packages with the same name as the new + * package. + * 3. While we are doing this we check our extracted packages MD5s, to make + * sure that the package is OK. */ boolean -conflict_package(package *pkg) +check_package(package *pkg, match_list *ml) { name_entry *n; - match_list ml = { PLIST_HEAD_INITIALIZER }; match_entry *m; + pkg_entry *pe; + plist_entry *p; + which_list wl = { PLIST_HEAD_INITIALIZER }; + which_entry *w, *wtmp; + char tmp[PATH_MAX], tmp2[PATH_MAX], *dir = "."; - if (pkg == NULL) + if (pkg == NULL || ml == NULL) return FALSE; + free_match(ml); PLIST_FOREACH(n, &pkg->conflicts) - match_pkg_entry(&ml, n->name); - if (PLIST_EMPTY(&ml)) - return FALSE; - PLIST_FOREACH(m, &ml) { - msg_warn("This package conflicts with '%s', which is already installed.%s\n", - basename_of(m->pe->dbdir), - (!PkgMgr.force ? "" : " (but I'll overwrite it)")); + match_pkg_entry(ml, n->name); + if (!PLIST_EMPTY(ml)) { + PLIST_FOREACH(m, ml) { + msg_warn("This package conflicts with '%s', which is already " + "installed.%s", basename_of(m->pe->dbdir), + (!PkgMgr.force ? "" : " (but I'll overwrite it)")); + } + if (!PkgMgr.force) + return TRUE; } - return TRUE; + PLIST_FOREACH(p, &pkg->plist) { + switch(p->type) { + case PLIST_CWD: + dir = p->name; + break; + case PLIST_FILE: + if (!NULLSTR(p->md5) && !check_md5(p->name, p->md5)) { + msg_warn("The file '%s' does not match the checksum " + "given in the package! This package might be corrupt, " + "or be trojaned! It is suggested that you do NOT force " + "installation unless you are sure!", p->name); + if (!PkgMgr.force) { + free_which(&wl); + return TRUE; + } + } + if (p->ignore) + break; + snprintf(tmp, PATH_MAX, "%s/%s", dir, p->name); + add_which_entry(&wl, WHICH_FILE, tmp); + break; + default: + break; + } + } + /* Convert the list of conflicting files into a list of packages */ + pkgroot_of(tmp, pkg->name, PATH_MAX); + PLIST_REMEACH(w, &wl, wtmp) { + if ((pe = scan_which_entry(w)) == NULL) + continue; + pkgroot_of(tmp2, pe->dbdir, PATH_MAX); + if (strpcmp(tmp, tmp2) == 0) { + PLIST_REMOVE(&wl, w, wtmp); + free(w); + add_match_entry(ml, pe); + } + } + /* If there are files left, then we can't upgrade! */ + if (!PLIST_EMPTY(&wl)) { + msg_warn("This package %s over-write the following " + "installed files:", (!PkgMgr.force ? "would" : "will")); + PLIST_FOREACH(w, &wl) { + pe = scan_which_entry(w); + msg_warn("%s (installed by %s)", w->file, + (pe == NULL ? "unknown" : basename_of(pe->dbdir))); + } + free_which(&wl); + if (!PkgMgr.force) + return TRUE; + } + /* Now add packages with the same origin */ + snprintf(tmp2, PATH_MAX, "%s:%s", pkg->origin, tmp); + pkg_mgr_origin(ml, tmp2); + if (PkgMgr.verbose && !PLIST_EMPTY(ml)) { + msg_verbose("Attempting to upgrade the following installed packages:\n"); + PLIST_FOREACH(m, ml) + msg_verbose("%s\n", basename_of(m->pe->dbdir)); + } + return FALSE; } /* @@ -1088,7 +1160,6 @@ if (from == NULL || to == NULL) return FAIL; - /* XXX: (jlea) Should we have state checks here? */ /* XXX: (jlea) We should compare pkgroot_of() the names, and bail if they are not the same? We should also compare prefix! */ /* @@ -1202,6 +1273,10 @@ strlcpy(d->file, to->origin, PATH_MAX); delete_name_entry(&from->requires, m->pe->pkg->name); add_name_entry(&to->requires, m->pe->pkg->name); + m->pe->status = PKG_CHANGED; + if (write_pkg_entry(m->pe) == FAIL) + return FAIL; + cleanup_pkg_entry(m->pe); } free_match(&ml); free_name(&nl); 1.3 +0 -72 freepkg/lib/which.c Index: which.c =================================================================== RCS file: /cvsroot/fpkg/freepkg/lib/which.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- which.c 29 Apr 2004 14:14:08 -0000 1.2 +++ which.c 3 May 2004 11:41:55 -0000 1.3 @@ -165,75 +165,3 @@ fclose(fp); return SUCCESS; } - -/* - * Check our list of files against a package's plist, to see if we have a - * match. Then check to see if the DB agrees. Blow it away if it lies... - */ -error_code -verify_scan(which_list *wl, pkg_entry *pe) -{ - pkg_entry *db; - plist_entry *p; - which_entry *w; - char *dir = "."; - char tmp[PATH_MAX], rp[PATH_MAX], cwd[PATH_MAX]; - - if (wl == NULL || pe == NULL) - return FAIL; - if (pe->status != PKG_REGISTERED) - return FAIL; - if (scan_pkg_entry(pe) == FAIL) - return FAIL; - if (!getcwd(cwd, PATH_MAX)) - strlcpy(cwd, PkgMgr.wrkdir, PATH_MAX); - PLIST_FOREACH(p, &pe->pkg->plist) { - switch(p->type) { - case PLIST_CWD: - dir = p->name; - break; - case PLIST_FILE: - if (p->ignore) - break; - snprintf(tmp, PATH_MAX, "%s/%s", dir, p->name); - if (!isfile(tmp)) - break; - realpath(tmp, rp); - PLIST_FOREACH(w, wl) { - if (strcmp(rp, w->file) == 0 - && (db = scan_which_entry(w)) != pe - && (open_filedb(TRUE) == FAIL - || (db = scan_which_entry(w)) != pe)) { - msg_error(2, "Failed to fix database!"); - enter_dir(cwd); - return FAIL; - } - } - break; - default: - break; - } - } - enter_dir(cwd); - return SUCCESS; -} - -/* - * Check a the DB results of a scan against the installed packages. - */ -error_code -verify_which(which_list *wl) -{ - pkg_entry *pe; - - if (wl == NULL) - return FAIL; - PLIST_FOREACH(pe, &PkgMgr) { - if (pe->status == PKG_REGISTERED) { - if (verify_scan(wl, pe) == FAIL) - return FAIL; - cleanup_pkg_entry(pe); - } - } - return SUCCESS; -} |