* Re-added a compare function for syncpkg's - it was removed without thinking

properly
* Error when re-reading the DB for replacements, wrong info level
* Removed an duplicate debug message "checking for package replacements"
* Check ignorepkg for REAL upgrades...
* Properly check the NOSAVE flag
* some unlink_file (remove.c) cleanup
* fix indent level on handle.c
* Force libalpm paths to end with a '/' char
* Fixed 'target' looping in conflict.c (pmsyncpkg_t, not pmpkg_t)
* Added some debug output to cache and db scanning

** All pactest tests succeed again, yay **
This commit is contained in:
Aaron Griffin 2007-02-21 06:44:14 +00:00
parent 1334f5c56c
commit 436f36c76b
9 changed files with 114 additions and 62 deletions

View file

@ -35,8 +35,8 @@ extern "C" {
*/ */
#define PM_ROOT "/" #define PM_ROOT "/"
#define PM_DBPATH "var/lib/pacman" #define PM_DBPATH "var/lib/pacman/"
#define PM_CACHEDIR "var/cache/pacman/pkg" #define PM_CACHEDIR "var/cache/pacman/pkg/"
#define PM_LOCK "tmp/pacman.lck" #define PM_LOCK "tmp/pacman.lck"

View file

@ -72,6 +72,7 @@ int _alpm_db_open(pmdb_t *db)
RET_ERR(PM_ERR_DB_NULL, -1); RET_ERR(PM_ERR_DB_NULL, -1);
} }
_alpm_log(PM_LOG_DEBUG, _("opening database from path '%s'"), db->path);
db->handle = opendir(db->path); db->handle = opendir(db->path);
if(db->handle == NULL) { if(db->handle == NULL) {
RET_ERR(PM_ERR_DB_OPEN, -1); RET_ERR(PM_ERR_DB_OPEN, -1);
@ -154,8 +155,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, pmdbinfrq_t inforeq)
if(!found) { if(!found) {
return(NULL); return(NULL);
} }
} else { } else { /* target == NULL, full scan */
/* normal iteration */
int isdir = 0; int isdir = 0;
while(!isdir) { while(!isdir) {
ent = readdir(db->handle); ent = readdir(db->handle);
@ -176,6 +176,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, pmdbinfrq_t inforeq)
pkg = _alpm_pkg_new(NULL, NULL); pkg = _alpm_pkg_new(NULL, NULL);
if(pkg == NULL) { if(pkg == NULL) {
_alpm_log(PM_LOG_DEBUG, _("db scan could not find package: %s"), target);
return(NULL); return(NULL);
} }
if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version, 0) == -1) { if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version, 0) == -1) {
@ -188,6 +189,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, pmdbinfrq_t inforeq)
} }
} }
_alpm_log(PM_LOG_DEBUG, _("db scan found package: %s"), pkg->name);
return(pkg); return(pkg);
} }

View file

@ -61,6 +61,7 @@ int _alpm_db_load_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
_alpm_db_rewind(db); _alpm_db_rewind(db);
while((info = _alpm_db_scan(db, NULL, infolevel)) != NULL) { while((info = _alpm_db_scan(db, NULL, infolevel)) != NULL) {
_alpm_log(PM_LOG_DEBUG, _("adding '%s' to package cache for db '%s'"), info->name, db->treename);
info->origin = PKG_FROM_CACHE; info->origin = PKG_FROM_CACHE;
info->data = db; info->data = db;
/* add to the collection */ /* add to the collection */
@ -104,6 +105,9 @@ alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
_alpm_db_ensure_pkgcache(db, infolevel); _alpm_db_ensure_pkgcache(db, infolevel);
if(!db->pkgcache) {
_alpm_log(PM_LOG_DEBUG, _("error: pkgcache is NULL for db %s"), db->treename);
}
return(db->pkgcache); return(db->pkgcache);
} }

View file

@ -379,9 +379,16 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
/* stat the file - if it exists and is not a dir, do some checks */ /* stat the file - if it exists and is not a dir, do some checks */
if(lstat(path, &buf) == 0 && !S_ISDIR(buf.st_mode)) { if(lstat(path, &buf) == 0 && !S_ISDIR(buf.st_mode)) {
/* Look at all the targets to see if file has changed hands */ /* Look at all the targets to see if file has changed hands */
for(k = targets; k; k = k->next) { for(k = targets; k; k = k->next) {
p2 = (pmpkg_t *)k->data; pmsyncpkg_t *sync = k->data;
if(!sync) {
continue;
}
p2 = sync->pkg;
/* Ensure we aren't looking at current package */ /* Ensure we aren't looking at current package */
if(p2 == p1) { if(p2 == p1) {
continue; continue;
@ -404,6 +411,7 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
_alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s", filestr); _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s", filestr);
} }
} else { } else {
_alpm_log(PM_LOG_DEBUG, "file found in conflict: %s", filestr);
conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE, conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE,
filestr, p1->name, NULL); filestr, p1->name, NULL);
break; break;

View file

@ -71,7 +71,7 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
FREE(db); FREE(db);
RET_ERR(PM_ERR_MEMORY, NULL); RET_ERR(PM_ERR_MEMORY, NULL);
} }
sprintf(db->path, "%s%s/%s", root, dbpath, treename); sprintf(db->path, "%s%s%s", root, dbpath, treename);
STRNCPY(db->treename, treename, PATH_MAX); STRNCPY(db->treename, treename, PATH_MAX);

View file

@ -66,6 +66,7 @@ pmhandle_t *_alpm_handle_new()
/* see if we're root or not (fakeroot does not count) */ /* see if we're root or not (fakeroot does not count) */
#ifndef FAKEROOT #ifndef FAKEROOT
if(handle->uid == 0 && !getenv("FAKEROOTKEY")) { if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
/* } make vim indent work - stupid ifdef's */
#else #else
if(handle->uid == 0) { if(handle->uid == 0) {
#endif #endif
@ -151,19 +152,49 @@ void SYMEXPORT alpm_option_set_logmask(unsigned short mask) { handle->logmask =
void alpm_option_set_root(const char *root) void alpm_option_set_root(const char *root)
{ {
if(handle->root) FREE(handle->root); if(handle->root) FREE(handle->root);
if(root) handle->root = strdup(root); if(root) {
/* verify root ends in a '/' */
int rootlen = strlen(root);
if(root[rootlen-1] != '/') {
rootlen += 1;
}
handle->root = calloc(rootlen+1, sizeof(char));
strncpy(handle->root, root, rootlen);
handle->root[rootlen-1] = '/';
_alpm_log(PM_LOG_DEBUG, _("option 'root' = %s"), handle->root);
}
} }
void SYMEXPORT alpm_option_set_dbpath(const char *dbpath) void SYMEXPORT alpm_option_set_dbpath(const char *dbpath)
{ {
if(handle->dbpath) FREE(handle->dbpath); if(handle->dbpath) FREE(handle->dbpath);
if(dbpath) handle->dbpath = strdup(dbpath); if(dbpath) {
/* verify dbpath ends in a '/' */
int dbpathlen = strlen(dbpath);
if(dbpath[dbpathlen-1] != '/') {
dbpathlen += 1;
}
handle->dbpath = calloc(dbpathlen+1, sizeof(char));
strncpy(handle->dbpath, dbpath, dbpathlen);
handle->dbpath[dbpathlen-1] = '/';
_alpm_log(PM_LOG_DEBUG, _("option 'dbpath' = %s"), handle->dbpath);
}
} }
void alpm_option_set_cachedir(const char *cachedir) void alpm_option_set_cachedir(const char *cachedir)
{ {
if(handle->cachedir) FREE(handle->cachedir); if(handle->cachedir) FREE(handle->cachedir);
if(cachedir) handle->cachedir = strdup(cachedir); if(cachedir) {
/* verify cachedir ends in a '/' */
int cachedirlen = strlen(cachedir);
if(cachedir[cachedirlen-1] != '/') {
cachedirlen += 1;
}
handle->cachedir = calloc(cachedirlen+1, sizeof(char));
strncpy(handle->cachedir, cachedir, cachedirlen);
handle->cachedir[cachedirlen-1] = '/';
_alpm_log(PM_LOG_DEBUG, _("option 'cachedir' = %s"), handle->cachedir);
}
} }
void alpm_option_set_logfile(const char *logfile) void alpm_option_set_logfile(const char *logfile)
@ -252,4 +283,4 @@ void alpm_option_set_usecolor(unsigned short usecolor)
handle->use_color = usecolor; handle->use_color = usecolor;
} }
/* vim: set ts=2 sw=2 et: */ /* vim: set ts=2 sw=2 noet: */

View file

@ -69,7 +69,7 @@ extern pmhandle_t *handle;
#define FREEHANDLE(p) do { if (p) { _alpm_handle_free(p); p = NULL; } } while (0) #define FREEHANDLE(p) do { if (p) { _alpm_handle_free(p); p = NULL; } } while (0)
pmhandle_t *_alpm_handle_new(void); pmhandle_t *_alpm_handle_new();
int _alpm_handle_free(pmhandle_t *handle); int _alpm_handle_free(pmhandle_t *handle);
#endif /* _ALPM_HANDLE_H */ #endif /* _ALPM_HANDLE_H */

View file

@ -206,10 +206,11 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
FREE(hash); FREE(hash);
} }
if(!needbackup && trans->type == PM_TRANS_TYPE_UPGRADE) { if(trans->type == PM_TRANS_TYPE_UPGRADE) {
/* check noupgrade */ /* check noupgrade */
if(alpm_list_find_str(handle->noupgrade, lp->data)) { if(alpm_list_find_str(handle->noupgrade, lp->data)) {
needbackup = 1; _alpm_log(PM_LOG_DEBUG, _("Skipping removal of '%s' due to NoUpgrade"), file);
return;
} }
} }
@ -232,19 +233,23 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
* explanation. */ * explanation. */
if(alpm_list_find_str(trans->skip_remove, file)) { if(alpm_list_find_str(trans->skip_remove, file)) {
_alpm_log(PM_LOG_DEBUG, _("%s is in trans->skip_remove, skipping removal"), file); _alpm_log(PM_LOG_DEBUG, _("%s is in trans->skip_remove, skipping removal"), file);
return;
} else if(needbackup) { } else if(needbackup) {
/* if the file is flagged, back it up to .pacsave */ /* if the file is flagged, back it up to .pacsave */
if(!(trans->type == PM_TRANS_TYPE_UPGRADE)) { if(!(trans->type == PM_TRANS_TYPE_UPGRADE)) {
/* if it was an upgrade, the file would be left alone because /* if it was an upgrade, the file would be left alone because
* pacman_add() would handle it */ * pacman_add() would handle it */
if(!(trans->type & PM_TRANS_FLAG_NOSAVE)) { if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
char newpath[PATH_MAX]; char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s.pacsave", file); snprintf(newpath, PATH_MAX, "%s.pacsave", file);
rename(file, newpath); rename(file, newpath);
_alpm_log(PM_LOG_WARNING, _("%s saved as %s"), file, newpath); _alpm_log(PM_LOG_WARNING, _("%s saved as %s"), file, newpath);
} return;
}
} else { } else {
_alpm_log(PM_LOG_DEBUG, _("transaction is set to NOSAVE, not backing up '%s'"), file);
}
}
}
_alpm_log(PM_LOG_DEBUG, _("unlinking %s"), file); _alpm_log(PM_LOG_DEBUG, _("unlinking %s"), file);
int list_count = alpm_list_count(trans->packages); /* this way we don't have to call alpm_list_count twice during PROGRESS */ int list_count = alpm_list_count(trans->packages); /* this way we don't have to call alpm_list_count twice during PROGRESS */
@ -256,7 +261,6 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
} }
} }
} }
}
int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db) int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
{ {

View file

@ -128,7 +128,7 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
/* check for "recommended" package replacements */ /* check for "recommended" package replacements */
_alpm_log(PM_LOG_DEBUG, _("checking for package replacements")); _alpm_log(PM_LOG_DEBUG, _("checking for package replacements"));
for(i = dbs_sync; i; i = i->next) { for(i = dbs_sync; i; i = i->next) {
for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) { for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DEPENDS); j; j = j->next) {
pmpkg_t *spkg = j->data; pmpkg_t *spkg = j->data;
for(k = spkg->replaces; k; k = k->next) { for(k = spkg->replaces; k; k = k->next) {
alpm_list_t *m; alpm_list_t *m;
@ -194,7 +194,6 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
ALPM_LOG_FUNC; ALPM_LOG_FUNC;
/* check for "recommended" package replacements */ /* check for "recommended" package replacements */
_alpm_log(PM_LOG_DEBUG, _("checking for package replacements"));
if( find_replacements(trans, db_local, dbs_sync) == 0 ) { if( find_replacements(trans, db_local, dbs_sync) == 0 ) {
/* match installed packages with the sync dbs and compare versions */ /* match installed packages with the sync dbs and compare versions */
_alpm_log(PM_LOG_DEBUG, _("checking for package upgrades")); _alpm_log(PM_LOG_DEBUG, _("checking for package upgrades"));
@ -229,6 +228,10 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
/* compare versions and see if we need to upgrade */ /* compare versions and see if we need to upgrade */
if(alpm_pkg_compare_versions(local, spkg)) { if(alpm_pkg_compare_versions(local, spkg)) {
if(alpm_list_find_str(handle->ignorepkg, local->name)) {
_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s => %s)"),
local->name, local->version, local->version, spkg->version);
} else {
_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"), _alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"),
local->name, local->version, local->version, spkg->version); local->name, local->version, local->version, spkg->version);
if(!find_pkginsync(spkg->name, trans->packages)) { if(!find_pkginsync(spkg->name, trans->packages)) {
@ -245,6 +248,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
} }
} }
} }
}
return(0); return(0);
} }
@ -358,11 +362,10 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
/* Helper functions for alpm_list_remove /* Helper functions for alpm_list_remove
*/ */
/* removed - use pkg_cmp all of the time static int syncpkg_cmp(const void *s1, const void *s2)
static int ptr_cmp(const void *s1, const void *s2)
{ {
return(strcmp(((pmsyncpkg_t *)s1)->pkg->name, ((pmsyncpkg_t *)s2)->pkg->name)); return(strcmp(((pmsyncpkg_t *)s1)->pkg->name, ((pmsyncpkg_t *)s2)->pkg->name));
}*/ }
static int pkg_cmp(const void *p1, const void *p2) static int pkg_cmp(const void *p1, const void *p2)
{ {
@ -554,8 +557,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
if(rmpkg) { if(rmpkg) {
pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages); pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages);
void *vpkg; void *vpkg;
_alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rmpkg); _alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rsync->pkg->name);
trans->packages = alpm_list_remove(trans->packages, rsync, pkg_cmp, &vpkg); trans->packages = alpm_list_remove(trans->packages, rsync, syncpkg_cmp, &vpkg);
FREESYNC(vpkg); FREESYNC(vpkg);
continue; continue;
} }
@ -592,7 +595,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* remove it from the target list */ /* remove it from the target list */
void *vpkg; void *vpkg;
_alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), miss->depend.name); _alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), miss->depend.name);
trans->packages = alpm_list_remove(trans->packages, rsync, pkg_cmp, &vpkg); trans->packages = alpm_list_remove(trans->packages, rsync, syncpkg_cmp, &vpkg);
FREESYNC(vpkg); FREESYNC(vpkg);
} }
} else { } else {