Date: Wednesday, January 31, 2007 @ 01:10:22 Author: aaron Path: /home/cvs-pacman/pacman-lib Modified: lib/libalpm/add.c (1.108 -> 1.109) lib/libalpm/alpm.c (1.109 -> 1.110) lib/libalpm/alpm.h (1.69 -> 1.70) lib/libalpm/be_files.c (1.23 -> 1.24) lib/libalpm/db.c (1.58 -> 1.59) lib/libalpm/deps.c (1.63 -> 1.64) lib/libalpm/handle.c (1.30 -> 1.31) lib/libalpm/remove.c (1.59 -> 1.60) lib/libalpm/sync.c (1.95 -> 1.96) lib/libalpm/util.c (1.43 -> 1.44) src/pacman/add.c (1.26 -> 1.27) src/pacman/conf.c (1.21 -> 1.22) src/pacman/conf.h (1.13 -> 1.14) src/pacman/deptest.c (1.12 -> 1.13) src/pacman/log.c (1.25 -> 1.26) src/pacman/pacman.c (1.84 -> 1.85) src/pacman/query.c (1.19 -> 1.20) src/pacman/remove.c (1.26 -> 1.27) src/pacman/sync.c (1.103 -> 1.104) Debug logging changes: * The --debug params were goofy. New setup allows --debug without params, --debug=<level> where level 1=debug output, 2=debug and download output, 3=debug, download, and function tracing output. This seems more sane to me. * Removed PM_LOG_FLOW1 and PM_LOG_FLOW2. They were just confusing. When adding new functions, it is near impossible to determin if your output should be "flow1" or "flow2" without tracking all the way up the call chain. Rarely would one ever say "ok, lets just show "flow2" output. These have both been replaced with PM_LOG_DEBUG * Removed the need for the root parameter on alpm_initialize. it is now defaulted to PM_ROOT just like dbpath and cachedir. This allows alpm to be initialized BEFORE option parsing in the front end, saving us some duplicate variables in the frontend. * Cleaned up front end variables due to early alpm_initialize call. ------------------------+ lib/libalpm/add.c | 38 ++++++++++++------------ lib/libalpm/alpm.c | 24 ++++----------- lib/libalpm/alpm.h | 14 +++------ lib/libalpm/be_files.c | 2 - lib/libalpm/db.c | 4 +- lib/libalpm/deps.c | 4 +- lib/libalpm/handle.c | 2 + lib/libalpm/remove.c | 26 ++++++++-------- lib/libalpm/sync.c | 44 ++++++++++++++-------------- lib/libalpm/util.c | 2 - src/pacman/add.c | 6 +-- src/pacman/conf.c | 3 - src/pacman/conf.h | 5 --- src/pacman/deptest.c | 2 - src/pacman/log.c | 11 ++----- src/pacman/pacman.c | 72 ++++++++++++++++++++++++++--------------------- src/pacman/query.c | 2 - src/pacman/remove.c | 2 - src/pacman/sync.c | 4 +- 19 files changed, 127 insertions(+), 140 deletions(-) Index: pacman-lib/lib/libalpm/add.c diff -u pacman-lib/lib/libalpm/add.c:1.108 pacman-lib/lib/libalpm/add.c:1.109 --- pacman-lib/lib/libalpm/add.c:1.108 Tue Jan 30 21:58:12 2007 +++ pacman-lib/lib/libalpm/add.c Wed Jan 31 01:10:21 2007 @@ -126,7 +126,7 @@ return(add_faketarget(trans, name)); } - _alpm_log(PM_LOG_FLOW2, _("loading target '%s'"), name); + _alpm_log(PM_LOG_DEBUG, _("loading target '%s'"), name); /* TODO FS#5120 we need a better way to check if a package is a valid package, * and read the metadata instead of relying on the filename for package name @@ -188,7 +188,7 @@ } } - _alpm_log(PM_LOG_FLOW2, _("reading '%s' metadata"), pkgname); + _alpm_log(PM_LOG_DEBUG, _("reading '%s' metadata"), pkgname); info = _alpm_pkg_load(name); if(info == NULL) { /* pm_errno is already set by pkg_load() */ @@ -241,7 +241,7 @@ EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); /* look for unsatisfied dependencies */ - _alpm_log(PM_LOG_FLOW1, _("looking for unsatisfied dependencies")); + _alpm_log(PM_LOG_DEBUG, _("looking for unsatisfied dependencies")); lp = _alpm_checkdeps(trans, db, trans->type, trans->packages); if(lp != NULL) { if(data) { @@ -253,7 +253,7 @@ } /* no unsatisfied deps, so look for conflicts */ - _alpm_log(PM_LOG_FLOW1, _("looking for conflicts")); + _alpm_log(PM_LOG_DEBUG, _("looking for conflicts")); lp = _alpm_checkconflicts(db, trans->packages); for(i = lp; i; i = i->next) { int skip_this = 0; @@ -292,7 +292,7 @@ } /* re-order w.r.t. dependencies */ - _alpm_log(PM_LOG_FLOW1, _("sorting by dependencies")); + _alpm_log(PM_LOG_DEBUG, _("sorting by dependencies")); lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_ADD); /* free the old alltargs */ FREELISTPTR(trans->packages); @@ -304,7 +304,7 @@ /* Cleaning up */ EVENT(trans, PM_TRANS_EVT_CLEANUP_START, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("cleaning up")); + _alpm_log(PM_LOG_DEBUG, _("cleaning up")); for (lp=trans->packages; lp!=NULL; lp=lp->next) { info=(pmpkg_t *)lp->data; for (rmlist=info->removes; rmlist!=NULL; rmlist=rmlist->next) { @@ -321,7 +321,7 @@ EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("looking for file conflicts")); + _alpm_log(PM_LOG_DEBUG, _("looking for file conflicts")); lp = _alpm_db_find_conflicts(db, trans, handle->root, &skiplist); if(lp != NULL) { if(data) { @@ -388,7 +388,7 @@ if(local) { EVENT(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL); cb_state = PM_TRANS_PROGRESS_UPGRADE_START; - _alpm_log(PM_LOG_FLOW1, _("upgrading package %s-%s"), info->name, info->version); + _alpm_log(PM_LOG_DEBUG, _("upgrading package %s-%s"), info->name, info->version); if((what = (char *)malloc(strlen(info->name)+1)) == NULL) { RET_ERR(PM_ERR_MEMORY, -1); } @@ -420,7 +420,7 @@ if(oldpkg) { pmtrans_t *tr; - _alpm_log(PM_LOG_FLOW1, _("removing old package first (%s-%s)"), oldpkg->name, oldpkg->version); + _alpm_log(PM_LOG_DEBUG, _("removing old package first (%s-%s)"), oldpkg->name, oldpkg->version); tr = _alpm_trans_new(); if(tr == NULL) { RET_ERR(PM_ERR_TRANS_ABORT, -1); @@ -450,7 +450,7 @@ if(!pmo_upgrade) { EVENT(trans, PM_TRANS_EVT_ADD_START, info, NULL); cb_state = PM_TRANS_PROGRESS_ADD_START; - _alpm_log(PM_LOG_FLOW1, _("adding package %s-%s"), info->name, info->version); + _alpm_log(PM_LOG_DEBUG, _("adding package %s-%s"), info->name, info->version); if((what = (char *)malloc(strlen(info->name)+1)) == NULL) { RET_ERR(PM_ERR_MEMORY, -1); } @@ -461,11 +461,11 @@ _alpm_runscriptlet(handle->root, info->data, "pre_install", info->version, NULL, trans); } } else { - _alpm_log(PM_LOG_FLOW1, _("adding new package %s-%s"), info->name, info->version); + _alpm_log(PM_LOG_DEBUG, _("adding new package %s-%s"), info->name, info->version); } if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) { - _alpm_log(PM_LOG_FLOW1, _("extracting files")); + _alpm_log(PM_LOG_DEBUG, _("extracting files")); /* Extract the package */ if ((archive = archive_read_new ()) == NULL) @@ -685,7 +685,7 @@ } if(installnew) { - _alpm_log(PM_LOG_FLOW2, _("extracting %s"), pathname); + _alpm_log(PM_LOG_DEBUG, _("extracting %s"), pathname); if(_alpm_copyfile(temp, expath)) { _alpm_log(PM_LOG_ERROR, _("could not copy %s to %s (%s)"), temp, pathname, strerror(errno)); errors++; @@ -705,9 +705,9 @@ close(fd); } else { if(!notouch) { - _alpm_log(PM_LOG_FLOW2, _("extracting %s"), pathname); + _alpm_log(PM_LOG_DEBUG, _("extracting %s"), pathname); } else { - _alpm_log(PM_LOG_FLOW2, _("%s is in NoUpgrade -- skipping"), pathname); + _alpm_log(PM_LOG_DEBUG, _("%s is in NoUpgrade -- skipping"), pathname); strncat(expath, ".pacnew", PATH_MAX); _alpm_log(PM_LOG_WARNING, _("extracting %s as %s.pacnew"), pathname, pathname); alpm_logaction(_("warning: extracting %s%s as %s"), handle->root, pathname, expath); @@ -800,8 +800,8 @@ /* remove the extra line feed appended by asctime() */ info->installdate[strlen(info->installdate)-1] = 0; - _alpm_log(PM_LOG_FLOW1, _("updating database")); - _alpm_log(PM_LOG_FLOW2, _("adding database entry '%s'"), info->name); + _alpm_log(PM_LOG_DEBUG, _("updating database")); + _alpm_log(PM_LOG_DEBUG, _("adding database entry '%s'"), info->name); if(_alpm_db_write(db, info, INFRQ_ALL)) { _alpm_log(PM_LOG_ERROR, _("could not update database entry %s-%s"), info->name, info->version); @@ -815,7 +815,7 @@ /* XXX: This is copy-pasta from remove.c - refactor */ /* update dependency packages' REQUIREDBY fields */ if(info->depends) { - _alpm_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); + _alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields")); } for(lp = info->depends; lp; lp = lp->next) { pmpkg_t *depinfo; @@ -875,7 +875,7 @@ /* run ldconfig if it exists */ if(handle->trans->state != STATE_INTERRUPTED) { - _alpm_log(PM_LOG_FLOW1, _("running \"ldconfig -r %s\""), handle->root); + _alpm_log(PM_LOG_DEBUG, _("running \"ldconfig -r %s\""), handle->root); _alpm_ldconfig(handle->root); } Index: pacman-lib/lib/libalpm/alpm.c diff -u pacman-lib/lib/libalpm/alpm.c:1.109 pacman-lib/lib/libalpm/alpm.c:1.110 --- pacman-lib/lib/libalpm/alpm.c:1.109 Tue Jan 30 03:14:10 2007 +++ pacman-lib/lib/libalpm/alpm.c Wed Jan 31 01:10:21 2007 @@ -72,13 +72,10 @@ /** Initializes the library. This must be called before any other * functions are called. - * @param root the full path of the root we'll be installing to (usually /) * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int SYMEXPORT alpm_initialize(const char *root) +int SYMEXPORT alpm_initialize() { - char str[PATH_MAX]; - ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1)); handle = _alpm_handle_new(); @@ -86,13 +83,6 @@ RET_ERR(PM_ERR_MEMORY, -1); } - STRNCPY(str, (root) ? root : PM_ROOT, PATH_MAX); - /* add a trailing '/' if there isn't one */ - if(str[strlen(str)-1] != '/') { - strcat(str, "/"); - } - handle->root = strdup(str); - return(0); } @@ -185,7 +175,7 @@ RET_ERR(PM_ERR_DB_NOT_FOUND, -1); } - _alpm_log(PM_LOG_FLOW1, _("unregistering database '%s'"), db->treename); + _alpm_log(PM_LOG_DEBUG, _("unregistering database '%s'"), db->treename); /* Cleanup */ _alpm_db_free_pkgcache(db); @@ -236,11 +226,11 @@ return(-1); } db->servers = alpm_list_add(db->servers, server); - _alpm_log(PM_LOG_FLOW2, _("adding new server to database '%s': protocol '%s', server '%s', path '%s'"), + _alpm_log(PM_LOG_DEBUG, _("adding new server to database '%s': protocol '%s', server '%s', path '%s'"), db->treename, server->s_url->scheme, server->s_url->host, server->s_url->doc); } else { FREELIST(db->servers); - _alpm_log(PM_LOG_FLOW2, _("serverlist flushed for '%s'"), db->treename); + _alpm_log(PM_LOG_DEBUG, _("serverlist flushed for '%s'"), db->treename); } return(0); @@ -312,7 +302,7 @@ snprintf(path, PATH_MAX, "%s%s/%s" PM_EXT_DB, handle->root, handle->dbpath, db->treename); /* remove the old dir */ - _alpm_log(PM_LOG_FLOW2, _("flushing database %s/%s"), handle->dbpath, db->treename); + _alpm_log(PM_LOG_DEBUG, _("flushing database %s/%s"), handle->dbpath, db->treename); for(lp = _alpm_db_get_pkgcache(db, INFRQ_NONE); lp; lp = lp->next) { if(_alpm_db_remove(db, lp->data) == -1) { if(lp->data) { @@ -497,7 +487,7 @@ } if(strcmp(sha1sum, pkg->sha1sum) == 0) { - _alpm_log(PM_LOG_FLOW1, _("checksums for package %s-%s are matching"), + _alpm_log(PM_LOG_DEBUG, _("checksums for package %s-%s are matching"), pkg->name, pkg->version); } else { _alpm_log(PM_LOG_ERROR, _("sha1sums do not match for package %s-%s"), @@ -546,7 +536,7 @@ } if(strcmp(md5sum, pkg->md5sum) == 0) { - _alpm_log(PM_LOG_FLOW1, _("checksums for package %s-%s are matching"), + _alpm_log(PM_LOG_DEBUG, _("checksums for package %s-%s are matching"), pkg->name, pkg->version); } else { _alpm_log(PM_LOG_ERROR, _("md5sums do not match for package %s-%s"), Index: pacman-lib/lib/libalpm/alpm.h diff -u pacman-lib/lib/libalpm/alpm.h:1.69 pacman-lib/lib/libalpm/alpm.h:1.70 --- pacman-lib/lib/libalpm/alpm.h:1.69 Tue Jan 30 21:58:12 2007 +++ pacman-lib/lib/libalpm/alpm.h Wed Jan 31 01:10:21 2007 @@ -63,7 +63,7 @@ * Library */ -int alpm_initialize(const char *root); +int alpm_initialize(); int alpm_release(void); /* @@ -72,13 +72,11 @@ /* Levels */ typedef enum _pmloglevel_t { - PM_LOG_DEBUG = 0x01, - PM_LOG_ERROR = 0x02, - PM_LOG_WARNING = 0x04, - PM_LOG_FLOW1 = 0x08, - PM_LOG_FLOW2 = 0x10, - PM_LOG_FUNCTION = 0x20, - PM_LOG_DOWNLOAD = 0x40 + PM_LOG_ERROR = 0x01, + PM_LOG_WARNING = 0x02, + PM_LOG_DEBUG = 0x04, + PM_LOG_DOWNLOAD = 0x08, + PM_LOG_FUNCTION = 0x10 } pmloglevel_t; typedef void (*alpm_cb_log)(unsigned short, char *); Index: pacman-lib/lib/libalpm/be_files.c diff -u pacman-lib/lib/libalpm/be_files.c:1.23 pacman-lib/lib/libalpm/be_files.c:1.24 --- pacman-lib/lib/libalpm/be_files.c:1.23 Tue Jan 30 03:14:10 2007 +++ pacman-lib/lib/libalpm/be_files.c Wed Jan 31 01:10:21 2007 @@ -56,7 +56,7 @@ /* ORE we should not simply unpack the archive, but better parse it and db_write each entry (see sync_load_dbarchive to get archive content) */ - _alpm_log(PM_LOG_FLOW2, _("unpacking database '%s'"), dbfile); + _alpm_log(PM_LOG_DEBUG, _("unpacking database '%s'"), dbfile); if(_alpm_unpack(dbfile, db->path, NULL)) { RET_ERR(PM_ERR_SYSTEM, -1); Index: pacman-lib/lib/libalpm/db.c diff -u pacman-lib/lib/libalpm/db.c:1.58 pacman-lib/lib/libalpm/db.c:1.59 --- pacman-lib/lib/libalpm/db.c:1.58 Tue Jan 30 03:14:10 2007 +++ pacman-lib/lib/libalpm/db.c Wed Jan 31 01:10:21 2007 @@ -174,12 +174,12 @@ } } - _alpm_log(PM_LOG_FLOW1, _("registering database '%s'"), treename); + _alpm_log(PM_LOG_DEBUG, _("registering database '%s'"), treename); /* make sure the database directory exists */ snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename); if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { - _alpm_log(PM_LOG_FLOW1, _("database directory '%s' does not exist -- try creating it"), path); + _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist -- try creating it"), path); if(_alpm_makepath(path) != 0) { RET_ERR(PM_ERR_SYSTEM, NULL); } Index: pacman-lib/lib/libalpm/deps.c diff -u pacman-lib/lib/libalpm/deps.c:1.63 pacman-lib/lib/libalpm/deps.c:1.64 --- pacman-lib/lib/libalpm/deps.c:1.63 Tue Jan 30 03:14:11 2007 +++ pacman-lib/lib/libalpm/deps.c Wed Jan 31 01:10:21 2007 @@ -495,7 +495,7 @@ /* see if it was explicitly installed */ if(dep->reason == PM_PKG_REASON_EXPLICIT) { - _alpm_log(PM_LOG_FLOW2, _("excluding %s -- explicitly installed"), dep->name); + _alpm_log(PM_LOG_DEBUG, _("excluding %s -- explicitly installed"), dep->name); needed = 1; } @@ -515,7 +515,7 @@ _alpm_log(PM_LOG_DEBUG, _("loading ALL info for '%s'"), pkg->name); _alpm_db_read(db, INFRQ_ALL, pkg); newtargs = alpm_list_add(newtargs, pkg); - _alpm_log(PM_LOG_FLOW2, _("adding '%s' to the targets"), pkg->name); + _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), pkg->name); newtargs = _alpm_removedeps(db, newtargs); } } Index: pacman-lib/lib/libalpm/handle.c diff -u pacman-lib/lib/libalpm/handle.c:1.30 pacman-lib/lib/libalpm/handle.c:1.31 --- pacman-lib/lib/libalpm/handle.c:1.30 Tue Jan 30 03:14:11 2007 +++ pacman-lib/lib/libalpm/handle.c Wed Jan 31 01:10:21 2007 @@ -77,8 +77,10 @@ handle->access = PM_ACCESS_RW; #endif + handle->root = strdup(PM_ROOT); handle->dbpath = strdup(PM_DBPATH); handle->cachedir = strdup(PM_CACHEDIR); + handle->logmask = PM_LOG_ERROR | PM_LOG_WARNING; return(handle); } Index: pacman-lib/lib/libalpm/remove.c diff -u pacman-lib/lib/libalpm/remove.c:1.59 pacman-lib/lib/libalpm/remove.c:1.60 --- pacman-lib/lib/libalpm/remove.c:1.59 Tue Jan 30 03:14:11 2007 +++ pacman-lib/lib/libalpm/remove.c Wed Jan 31 01:10:21 2007 @@ -89,7 +89,7 @@ } } - _alpm_log(PM_LOG_FLOW2, _("adding %s in the targets list"), info->name); + _alpm_log(PM_LOG_DEBUG, _("adding %s in the targets list"), info->name); trans->packages = alpm_list_add(trans->packages, info); return(0); @@ -107,7 +107,7 @@ if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) { EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("looking for unsatisfied dependencies")); + _alpm_log(PM_LOG_DEBUG, _("looking for unsatisfied dependencies")); lp = _alpm_checkdeps(trans, db, trans->type, trans->packages); if(lp != NULL) { if(trans->flags & PM_TRANS_FLAG_CASCADE) { @@ -117,7 +117,7 @@ pmdepmissing_t *miss = (pmdepmissing_t *)i->data; pmpkg_t *info = _alpm_db_scan(db, miss->depend.name, INFRQ_ALL); if(info) { - _alpm_log(PM_LOG_FLOW2, _("pulling %s in the targets list"), info->name); + _alpm_log(PM_LOG_DEBUG, _("pulling %s in the targets list"), info->name); trans->packages = alpm_list_add(trans->packages, info); } else { _alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping"), @@ -138,12 +138,12 @@ } if(trans->flags & PM_TRANS_FLAG_RECURSE) { - _alpm_log(PM_LOG_FLOW1, _("finding removable dependencies")); + _alpm_log(PM_LOG_DEBUG, _("finding removable dependencies")); trans->packages = _alpm_removedeps(db, trans->packages); } /* re-order w.r.t. dependencies */ - _alpm_log(PM_LOG_FLOW1, _("sorting by dependencies")); + _alpm_log(PM_LOG_DEBUG, _("sorting by dependencies")); lp = _alpm_sortbydeps(trans->packages, PM_TRANS_TYPE_REMOVE); /* free the old alltargs */ FREELISTPTR(trans->packages); @@ -212,7 +212,7 @@ } } if ( skipit ) { - _alpm_log(PM_LOG_FLOW2, _("skipping removal of %s as it has moved to another package"), + _alpm_log(PM_LOG_DEBUG, _("skipping removal of %s as it has moved to another package"), line); } else { /* if the file is flagged, back it up to .pacsave */ @@ -228,7 +228,7 @@ } } } else { - _alpm_log(PM_LOG_FLOW2, _("unlinking %s"), line); + _alpm_log(PM_LOG_DEBUG, _("unlinking %s"), line); int list_count = alpm_list_count(trans->packages); /* this way we don't have to call alpm_list_count twice during PROGRESS */ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, (double)(percent * 100), list_count, (list_count - alpm_list_count(targ) + 1)); ++(*position); @@ -262,7 +262,7 @@ if(trans->type != PM_TRANS_TYPE_UPGRADE) { EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL); - _alpm_log(PM_LOG_FLOW1, _("removing package %s-%s"), info->name, info->version); + _alpm_log(PM_LOG_DEBUG, _("removing package %s-%s"), info->name, info->version); /* run the pre-remove scriptlet if it exists */ if(info->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { @@ -273,7 +273,7 @@ if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) { int filenum = alpm_list_count(info->files); - _alpm_log(PM_LOG_FLOW1, _("removing files")); + _alpm_log(PM_LOG_DEBUG, _("removing files")); /* iterate through the list backwards, unlinking files */ for(lp = alpm_list_last(info->files); lp; lp = lp->prev) { @@ -290,8 +290,8 @@ } /* remove the package from the database */ - _alpm_log(PM_LOG_FLOW1, _("updating database")); - _alpm_log(PM_LOG_FLOW2, _("removing database entry '%s'"), info->name); + _alpm_log(PM_LOG_DEBUG, _("updating database")); + _alpm_log(PM_LOG_DEBUG, _("removing database entry '%s'"), info->name); if(_alpm_db_remove(db, info) == -1) { _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"), info->name, info->version); } @@ -300,7 +300,7 @@ } /* update dependency packages' REQUIREDBY fields */ - _alpm_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); + _alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields")); for(lp = info->depends; lp; lp = lp->next) { pmpkg_t *depinfo = NULL; pmdepend_t depend; @@ -355,7 +355,7 @@ /* run ldconfig if it exists */ if((trans->type != PM_TRANS_TYPE_UPGRADE) && (handle->trans->state != STATE_INTERRUPTED)) { - _alpm_log(PM_LOG_FLOW1, _("running \"ldconfig -r %s\""), handle->root); + _alpm_log(PM_LOG_DEBUG, _("running \"ldconfig -r %s\""), handle->root); _alpm_ldconfig(handle->root); } Index: pacman-lib/lib/libalpm/sync.c diff -u pacman-lib/lib/libalpm/sync.c:1.95 pacman-lib/lib/libalpm/sync.c:1.96 --- pacman-lib/lib/libalpm/sync.c:1.95 Tue Jan 30 03:14:11 2007 +++ pacman-lib/lib/libalpm/sync.c Wed Jan 31 01:10:21 2007 @@ -138,7 +138,7 @@ ALPM_LOG_FUNC; /* check for "recommended" package replacements */ - _alpm_log(PM_LOG_FLOW1, _("checking for package replacements")); + _alpm_log(PM_LOG_DEBUG, _("checking for package replacements")); for(i = dbs_sync; i; i = i->next) { for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) { pmpkg_t *spkg = j->data; @@ -183,7 +183,7 @@ sync->data = alpm_list_add(NULL, dummy); trans->packages = alpm_list_add(trans->packages, sync); } - _alpm_log(PM_LOG_FLOW2, _("%s-%s elected for upgrade (to be replaced by %s-%s)"), + _alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (to be replaced by %s-%s)"), lpkg->name, lpkg->version, spkg->name, spkg->version); } } @@ -205,10 +205,10 @@ ALPM_LOG_FUNC; /* check for "recommended" package replacements */ - _alpm_log(PM_LOG_FLOW1, _("checking for package replacements")); + _alpm_log(PM_LOG_DEBUG, _("checking for package replacements")); if( find_replacements(trans, db_local, dbs_sync) == 0 ) { /* match installed packages with the sync dbs and compare versions */ - _alpm_log(PM_LOG_FLOW1, _("checking for package upgrades")); + _alpm_log(PM_LOG_DEBUG, _("checking for package upgrades")); for(i = _alpm_db_get_pkgcache(db_local, INFRQ_NONE); i; i = i->next) { int cmp; int replace=0; @@ -254,11 +254,11 @@ local->name, local->version, spkg->version); } else if(istoonew(spkg)) { /* package too new (UpgradeDelay) */ - _alpm_log(PM_LOG_FLOW1, _("%s-%s: delaying upgrade of package (%s)"), + _alpm_log(PM_LOG_DEBUG, _("%s-%s: delaying upgrade of package (%s)"), local->name, local->version, spkg->version); /* check if spkg->name is already in the packages list. */ } else { - _alpm_log(PM_LOG_FLOW2, _("%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); if(!find_pkginsync(spkg->name, trans->packages)) { pmpkg_t *dummy = _alpm_pkg_new(local->name, local->version); @@ -314,7 +314,7 @@ if(spkg == NULL) { /* Search provides */ alpm_list_t *p; - _alpm_log(PM_LOG_FLOW2, _("target '%s' not found -- looking for provisions"), targ); + _alpm_log(PM_LOG_DEBUG, _("target '%s' not found -- looking for provisions"), targ); p = _alpm_db_whatprovides(dbs, targ); if(p == NULL) { RET_ERR(PM_ERR_PKG_NOT_FOUND, -1); @@ -337,7 +337,7 @@ } if(spkg == NULL) { /* Search provides */ - _alpm_log(PM_LOG_FLOW2, _("target '%s' not found -- looking for provisions"), targ); + _alpm_log(PM_LOG_DEBUG, _("target '%s' not found -- looking for provisions"), targ); for(j = dbs_sync; j && !spkg; j = j->next) { pmdb_t *dbs = j->data; alpm_list_t *p = _alpm_db_whatprovides(dbs, targ); @@ -389,7 +389,7 @@ FREEPKG(dummy); RET_ERR(PM_ERR_MEMORY, -1); } - _alpm_log(PM_LOG_FLOW2, _("adding target '%s' to the transaction set"), spkg->name); + _alpm_log(PM_LOG_DEBUG, _("adding target '%s' to the transaction set"), spkg->name); trans->packages = alpm_list_add(trans->packages, sync); } @@ -437,7 +437,7 @@ /* Resolve targets dependencies */ EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("resolving target's dependencies")); + _alpm_log(PM_LOG_DEBUG, _("resolving target's dependencies")); for(i = trans->packages; i; i = i->next) { pmpkg_t *spkg = ((pmsyncpkg_t *)i->data)->pkg; if(_alpm_resolvedeps(db_local, dbs_sync, spkg, list, trail, trans, data) == -1) { @@ -457,7 +457,7 @@ goto cleanup; } trans->packages = alpm_list_add(trans->packages, sync); - _alpm_log(PM_LOG_FLOW2, _("adding package %s-%s to the transaction targets"), + _alpm_log(PM_LOG_DEBUG, _("adding package %s-%s to the transaction targets"), spkg->name, spkg->version); } else { /* remove the original targets from the list if requested */ @@ -492,7 +492,7 @@ EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("looking for unresolvable dependencies")); + _alpm_log(PM_LOG_DEBUG, _("looking for unresolvable dependencies")); deps = _alpm_checkdeps(trans, db_local, PM_TRANS_TYPE_UPGRADE, list); if(deps) { if(data) { @@ -512,7 +512,7 @@ /* check for inter-conflicts and whatnot */ EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL); - _alpm_log(PM_LOG_FLOW1, _("looking for conflicts")); + _alpm_log(PM_LOG_DEBUG, _("looking for conflicts")); deps = _alpm_checkconflicts(db_local, list); if(deps) { int errorout = 0; @@ -523,7 +523,7 @@ pmsyncpkg_t *sync; pmpkg_t *local; - _alpm_log(PM_LOG_FLOW2, _("package '%s' is conflicting with '%s'"), + _alpm_log(PM_LOG_DEBUG, _("package '%s' is conflicting with '%s'"), miss->target, miss->depend.name); /* check if the conflicting package is one that's about to be removed/replaced. @@ -596,7 +596,7 @@ if(rmpkg) { pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages); void *vpkg; - _alpm_log(PM_LOG_FLOW2, _("removing '%s' from target list"), rmpkg); + _alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rmpkg); trans->packages = alpm_list_remove(trans->packages, rsync, pkg_cmp, &vpkg); FREESYNC(vpkg); continue; @@ -628,12 +628,12 @@ FREEPKG(sync->data); } /* append to the replaces list */ - _alpm_log(PM_LOG_FLOW2, _("electing '%s' for removal"), miss->depend.name); + _alpm_log(PM_LOG_DEBUG, _("electing '%s' for removal"), miss->depend.name); sync->data = alpm_list_add(sync->data, q); if(rsync) { /* remove it from the target list */ void *vpkg; - _alpm_log(PM_LOG_FLOW2, _("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); FREESYNC(vpkg); } @@ -707,7 +707,7 @@ } } if(list) { - _alpm_log(PM_LOG_FLOW1, _("checking dependencies of packages designated for removal")); + _alpm_log(PM_LOG_DEBUG, _("checking dependencies of packages designated for removal")); deps = _alpm_checkdeps(trans, db_local, PM_TRANS_TYPE_REMOVE, list); if(deps) { int errorout = 0; @@ -740,7 +740,7 @@ for(o = sp->pkg->provides; o && !pfound; o = o->next) { if(!strcmp(m->data, o->data)) { /* found matching provisio -- we're good to go */ - _alpm_log(PM_LOG_FLOW2, _("found '%s' as a provision for '%s' -- conflict aborted"), + _alpm_log(PM_LOG_DEBUG, _("found '%s' as a provision for '%s' -- conflict aborted"), sp->pkg->name, (char *)o->data); pfound = 1; } @@ -970,7 +970,7 @@ } } if(replaces) { - _alpm_log(PM_LOG_FLOW1, _("removing conflicting and to-be-replaced packages")); + _alpm_log(PM_LOG_DEBUG, _("removing conflicting and to-be-replaced packages")); if(_alpm_trans_prepare(tr, data) == -1) { _alpm_log(PM_LOG_ERROR, _("could not prepare removal transaction")); goto error; @@ -985,7 +985,7 @@ FREETRANS(tr); /* install targets */ - _alpm_log(PM_LOG_FLOW1, _("installing packages")); + _alpm_log(PM_LOG_DEBUG, _("installing packages")); tr = _alpm_trans_new(); if(tr == NULL) { _alpm_log(PM_LOG_ERROR, _("could not create transaction")); @@ -1028,7 +1028,7 @@ /* propagate replaced packages' requiredby fields to their new owners */ if(replaces) { - _alpm_log(PM_LOG_FLOW1, _("updating database for replaced packages' dependencies")); + _alpm_log(PM_LOG_DEBUG, _("updating database for replaced packages' dependencies")); for(i = trans->packages; i; i = i->next) { pmsyncpkg_t *sync = i->data; if(sync->type == PM_SYNC_TYPE_REPLACE) { Index: pacman-lib/lib/libalpm/util.c diff -u pacman-lib/lib/libalpm/util.c:1.43 pacman-lib/lib/libalpm/util.c:1.44 --- pacman-lib/lib/libalpm/util.c:1.43 Tue Jan 30 03:14:11 2007 +++ pacman-lib/lib/libalpm/util.c Wed Jan 31 01:10:22 2007 @@ -468,7 +468,7 @@ _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)"), root, strerror(errno)); } - _alpm_log(PM_LOG_FLOW2, _("executing %s script..."), script); + _alpm_log(PM_LOG_DEBUG, _("executing %s script..."), script); if(oldver) { snprintf(cmdline, PATH_MAX, "source %s %s %s %s", Index: pacman-lib/src/pacman/add.c diff -u pacman-lib/src/pacman/add.c:1.26 pacman-lib/src/pacman/add.c:1.27 --- pacman-lib/src/pacman/add.c:1.26 Tue Jan 30 23:42:39 2007 +++ pacman-lib/src/pacman/add.c Wed Jan 31 01:10:22 2007 @@ -67,7 +67,7 @@ ERR(NL, "%s\n", alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } @@ -124,7 +124,7 @@ switch(alpm_conflict_get_type(conflict)) { case PM_CONFLICT_TYPE_TARGET: MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), - config->root, + alpm_option_get_root(), alpm_conflict_get_file(conflict), alpm_conflict_get_target(conflict), alpm_conflict_get_ctarget(conflict)); @@ -132,7 +132,7 @@ case PM_CONFLICT_TYPE_FILE: MSG(NL, _("%s: %s%s exists in filesystem"), alpm_conflict_get_target(conflict), - config->root, + alpm_option_get_root(), alpm_conflict_get_file(conflict)); break; } Index: pacman-lib/src/pacman/conf.c diff -u pacman-lib/src/pacman/conf.c:1.21 pacman-lib/src/pacman/conf.c:1.22 --- pacman-lib/src/pacman/conf.c:1.21 Fri Jan 19 04:28:46 2007 +++ pacman-lib/src/pacman/conf.c Wed Jan 31 01:10:22 2007 @@ -26,7 +26,6 @@ #include <libintl.h> #include <alpm.h> -#include <alpm_list.h> /* pacman */ #include "util.h" #include "log.h" @@ -51,9 +50,7 @@ return(-1); } - FREE(config->root); FREE(config->configfile); - FREELIST(config->op_s_ignore); free(config); return(0); Index: pacman-lib/src/pacman/conf.h diff -u pacman-lib/src/pacman/conf.h:1.13 pacman-lib/src/pacman/conf.h:1.14 --- pacman-lib/src/pacman/conf.h:1.13 Fri Jan 19 04:28:46 2007 +++ pacman-lib/src/pacman/conf.h Wed Jan 31 01:10:22 2007 @@ -25,9 +25,6 @@ typedef struct __config_t { /* command line options */ - char *root; - const char *dbpath; - const char *cachedir; char *configfile; unsigned short op; unsigned short verbose; @@ -49,14 +46,12 @@ unsigned short op_s_clean; unsigned short op_s_dependsonly; unsigned short op_s_downloadonly; - alpm_list_t *op_s_ignore; unsigned short op_s_info; unsigned short op_s_sync; unsigned short op_s_search; unsigned short op_s_upgrade; unsigned short group; unsigned int flags; - unsigned short debug; unsigned short noask; unsigned int ask; } config_t; Index: pacman-lib/src/pacman/deptest.c diff -u pacman-lib/src/pacman/deptest.c:1.12 pacman-lib/src/pacman/deptest.c:1.13 --- pacman-lib/src/pacman/deptest.c:1.12 Wed Jan 24 03:51:51 2007 +++ pacman-lib/src/pacman/deptest.c Wed Jan 31 01:10:22 2007 @@ -67,7 +67,7 @@ ERR(NL, "%s", alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } Index: pacman-lib/src/pacman/log.c diff -u pacman-lib/src/pacman/log.c:1.25 pacman-lib/src/pacman/log.c:1.26 --- pacman-lib/src/pacman/log.c:1.25 Wed Jan 24 11:57:19 2007 +++ pacman-lib/src/pacman/log.c Wed Jan 31 01:10:22 2007 @@ -66,13 +66,10 @@ case PM_LOG_WARNING: sprintf(str, _("warning")); break; - case PM_LOG_FLOW1: - sprintf(str, _("flow1")); - break; - case PM_LOG_FLOW2: - sprintf(str, _("flow2")); - break; case PM_LOG_FUNCTION: + /* TODO we should increase the indent level when this occurs so we can see + * program flow easier. It'll be fun + */ sprintf(str, _("function")); break; default: @@ -82,7 +79,7 @@ #ifdef PACMAN_DEBUG /* If debug is on, we'll timestamp the output */ - if(config->debug&PM_LOG_DEBUG) { + if(alpm_option_get_logmask() & PM_LOG_DEBUG) { time_t t; struct tm *tmp; char timestr[10] = {0}; Index: pacman-lib/src/pacman/pacman.c diff -u pacman-lib/src/pacman/pacman.c:1.84 pacman-lib/src/pacman/pacman.c:1.85 --- pacman-lib/src/pacman/pacman.c:1.84 Thu Jan 25 21:13:16 2007 +++ pacman-lib/src/pacman/pacman.c Wed Jan 31 01:10:22 2007 @@ -251,7 +251,7 @@ {"noconfirm", no_argument, 0, 1000}, {"config", required_argument, 0, 1001}, {"ignore", required_argument, 0, 1002}, - {"debug", required_argument, 0, 1003}, + {"debug", optional_argument, 0, 1003}, {"noprogressbar", no_argument, 0, 1004}, {"noscriptlet", no_argument, 0, 1005}, {"ask", required_argument, 0, 1006}, @@ -259,6 +259,7 @@ }; char root[PATH_MAX]; struct stat st; + unsigned short logmask; while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) { if(opt < 0) { @@ -277,8 +278,32 @@ config->configfile = strndup(optarg, PATH_MAX); #endif break; - case 1002: config->op_s_ignore = alpm_list_add(config->op_s_ignore, strdup(optarg)); break; - case 1003: config->debug = atoi(optarg); break; + case 1002: alpm_option_add_ignorepkg(strdup(optarg)); break; + case 1003: + /* debug levels are made more 'human readable' than using a raw logmask + * here, we will ALWAYS set error and warning for now, though perhaps a + * --quiet option will remove these later */ + logmask = PM_LOG_ERROR | PM_LOG_WARNING; + + if(optarg) { + unsigned short debug = atoi(optarg); + printf("setting logmask to %s\n", optarg); + switch(debug) { + case 3: logmask |= PM_LOG_FUNCTION; /* fall through */ + case 2: logmask |= PM_LOG_DOWNLOAD; /*fall through */ + case 1: logmask |= PM_LOG_DEBUG; break; + default: + pm_fprintf(stderr, NL, _("error: '%s' is not a valid debug level"), optarg); + return(1); + } + printf("logmask = %d\n", logmask); + } else { + logmask |= PM_LOG_DEBUG; + } + /* progress bars get wonky with debug on, shut them off */ + config->noprogressbar = 1; + alpm_option_set_logmask(logmask); + break; case 1004: config->noprogressbar = 1; break; case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break; case 1006: config->noask = 1; config->ask = atoi(optarg); break; @@ -305,10 +330,9 @@ case 'b': if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { pm_fprintf(stderr, NL, _("error: '%s' is not a valid db path\n"), optarg); - exit(EXIT_FAILURE); + return(1); } alpm_option_set_dbpath(optarg); - config->dbpath = alpm_option_get_dbpath(optarg); break; case 'c': (config->op_s_clean)++; @@ -334,12 +358,11 @@ config->flags |= PM_TRANS_FLAG_PRINTURIS; break; case 'r': - printf("setting root path=%s\n", optarg); if(realpath(optarg, root) == NULL) { - perror(_("bad root path")); + pm_fprintf(stderr, NL, _("error: '%s' is not a valid root path\n"), optarg); return(1); } - config->root = strdup(root); + alpm_option_set_root(strdup(root)); break; case 's': config->op_s_search = 1; @@ -416,13 +439,17 @@ /* init config data */ config = config_new(); config->op = PM_OP_MAIN; - config->debug |= PM_LOG_ERROR; - config->debug |= PM_LOG_WARNING; /* disable progressbar if the output is redirected */ if(!isatty(1)) { config->noprogressbar = 1; } + /* initialize pm library */ + if(alpm_initialize() == -1) { + ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno)); + cleanup(1); + } + /* parse the command line */ ret = parseargs(argc, argv); if(ret != 0) { @@ -447,7 +474,7 @@ (config->op_s_search || config->group || config->op_q_list || config->op_q_info || config->flags & PM_TRANS_FLAG_PRINTURIS)) || (config->op == PM_OP_DEPTEST && !config->op_d_resolve) - || (config->root != NULL)) { + || (strcmp(alpm_option_get_root(), PM_ROOT) != 0)) { /* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */ /* special case: ignore root user check if -r is specified, fall back on * normal FS checking */ @@ -460,18 +487,7 @@ } #endif - if(config->root == NULL) { - config->root = strdup(PM_ROOT); - } - - /* initialize pm library */ - if(alpm_initialize(config->root) == -1) { - ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } - /* Setup logging as soon as possible, to print out maximum debugging info */ - alpm_option_set_logmask(config->debug); alpm_option_set_logcb(cb_log); if(config->configfile == NULL) { @@ -486,17 +502,9 @@ /* set library parameters */ alpm_option_set_dlcb(log_progress); - config->dbpath = alpm_option_get_dbpath(); - config->cachedir = alpm_option_get_cachedir(); - - alpm_list_t *i; - for(i = config->op_s_ignore; i; i = alpm_list_next(i)) { - alpm_option_add_ignorepkg(alpm_list_getdata(i)); - } - if(config->verbose > 0) { - printf("Root : %s\n", config->root); - printf("DBPath: %s\n", config->dbpath); + printf("Root : %s\n", alpm_option_get_root()); + printf("DBPath: %s\n", alpm_option_get_dbpath()); list_display(_("Targets:"), pm_targets); } Index: pacman-lib/src/pacman/query.c diff -u pacman-lib/src/pacman/query.c:1.19 pacman-lib/src/pacman/query.c:1.20 --- pacman-lib/src/pacman/query.c:1.19 Wed Jan 24 03:51:51 2007 +++ pacman-lib/src/pacman/query.c Wed Jan 31 01:10:22 2007 @@ -260,7 +260,7 @@ if(config->op_q_changelog) { char changelog[PATH_MAX]; snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog", - config->root, alpm_option_get_dbpath(), + alpm_option_get_root(), alpm_option_get_dbpath(), alpm_db_get_name(db_local), alpm_pkg_get_name(info), alpm_pkg_get_version(info)); Index: pacman-lib/src/pacman/remove.c diff -u pacman-lib/src/pacman/remove.c:1.26 pacman-lib/src/pacman/remove.c:1.27 --- pacman-lib/src/pacman/remove.c:1.26 Tue Jan 30 23:42:39 2007 +++ pacman-lib/src/pacman/remove.c Wed Jan 31 01:10:22 2007 @@ -77,7 +77,7 @@ ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } FREELIST(finaltargs); return(1); Index: pacman-lib/src/pacman/sync.c diff -u pacman-lib/src/pacman/sync.c:1.103 pacman-lib/src/pacman/sync.c:1.104 --- pacman-lib/src/pacman/sync.c:1.103 Tue Jan 30 13:25:54 2007 +++ pacman-lib/src/pacman/sync.c Wed Jan 31 01:10:22 2007 @@ -439,7 +439,7 @@ ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } @@ -488,7 +488,7 @@ ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); }