Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-02-21 06:44:14 +0000
committerAaron Griffin <aaron@archlinux.org>2007-02-21 06:44:14 +0000
commit436f36c76b74f7580da48e618dbdbd78037736fb (patch)
tree2ac3224aebed635bde3b6730c02cf3cbeb57f71c /lib/libalpm
parent1334f5c56c8394e69ad16f3b5269105e3dc42246 (diff)
* 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 **
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.h4
-rw-r--r--lib/libalpm/be_files.c6
-rw-r--r--lib/libalpm/cache.c4
-rw-r--r--lib/libalpm/conflict.c10
-rw-r--r--lib/libalpm/db.c2
-rw-r--r--lib/libalpm/handle.c79
-rw-r--r--lib/libalpm/handle.h2
-rw-r--r--lib/libalpm/remove.c26
-rw-r--r--lib/libalpm/sync.c43
9 files changed, 114 insertions, 62 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index d4f6720f..5a71cd86 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -35,8 +35,8 @@ extern "C" {
*/
#define PM_ROOT "/"
-#define PM_DBPATH "var/lib/pacman"
-#define PM_CACHEDIR "var/cache/pacman/pkg"
+#define PM_DBPATH "var/lib/pacman/"
+#define PM_CACHEDIR "var/cache/pacman/pkg/"
#define PM_LOCK "tmp/pacman.lck"
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 39b7c724..dad81972 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -72,6 +72,7 @@ int _alpm_db_open(pmdb_t *db)
RET_ERR(PM_ERR_DB_NULL, -1);
}
+ _alpm_log(PM_LOG_DEBUG, _("opening database from path '%s'"), db->path);
db->handle = opendir(db->path);
if(db->handle == NULL) {
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) {
return(NULL);
}
- } else {
- /* normal iteration */
+ } else { /* target == NULL, full scan */
int isdir = 0;
while(!isdir) {
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);
if(pkg == NULL) {
+ _alpm_log(PM_LOG_DEBUG, _("db scan could not find package: %s"), target);
return(NULL);
}
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);
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index e7c58a19..41038fe3 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -61,6 +61,7 @@ int _alpm_db_load_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
_alpm_db_rewind(db);
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->data = db;
/* 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);
+ if(!db->pkgcache) {
+ _alpm_log(PM_LOG_DEBUG, _("error: pkgcache is NULL for db %s"), db->treename);
+ }
return(db->pkgcache);
}
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index a5f9590f..2846d9e8 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -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 */
if(lstat(path, &buf) == 0 && !S_ISDIR(buf.st_mode)) {
+
/* Look at all the targets to see if file has changed hands */
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 */
if(p2 == p1) {
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);
}
} else {
+ _alpm_log(PM_LOG_DEBUG, "file found in conflict: %s", filestr);
conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_FILE,
filestr, p1->name, NULL);
break;
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 3d2d1c8a..f61487a5 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -71,7 +71,7 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
FREE(db);
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);
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index cfc7ac62..6e8e45e3 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -66,28 +66,29 @@ pmhandle_t *_alpm_handle_new()
/* see if we're root or not (fakeroot does not count) */
#ifndef FAKEROOT
if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
+ /* } make vim indent work - stupid ifdef's */
#else
- if(handle->uid == 0) {
+ if(handle->uid == 0) {
#endif
- handle->access = PM_ACCESS_RW;
- } else {
- handle->access = PM_ACCESS_RO;
- }
+ handle->access = PM_ACCESS_RW;
+ } else {
+ handle->access = PM_ACCESS_RO;
+ }
#else
handle->access = PM_ACCESS_RW;
#endif
- handle->root = strdup(PM_ROOT);
+ handle->root = strdup(PM_ROOT);
handle->dbpath = strdup(PM_DBPATH);
handle->cachedir = strdup(PM_CACHEDIR);
- handle->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
+ handle->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
return(handle);
}
int _alpm_handle_free(pmhandle_t *handle)
{
- ALPM_LOG_FUNC;
+ ALPM_LOG_FUNC;
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
@@ -139,7 +140,7 @@ unsigned short alpm_option_get_usecolor() { return handle->use_color; }
pmdb_t *alpm_option_get_localdb() { return handle->db_local; }
alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
{
- return handle->dbs_sync;
+ return handle->dbs_sync;
}
void SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb) { handle->logcb = cb; }
@@ -151,24 +152,54 @@ void SYMEXPORT alpm_option_set_logmask(unsigned short mask) { handle->logmask =
void alpm_option_set_root(const char *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)
{
- if(handle->dbpath) FREE(handle->dbpath);
- if(dbpath) handle->dbpath = strdup(dbpath);
+ if(handle->dbpath) FREE(handle->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)
{
- if(handle->cachedir) FREE(handle->cachedir);
- if(cachedir) handle->cachedir = strdup(cachedir);
+ if(handle->cachedir) FREE(handle->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)
{
- ALPM_LOG_FUNC;
+ ALPM_LOG_FUNC;
if(handle->logfile) {
FREE(handle->logfile);
@@ -185,12 +216,12 @@ void alpm_option_set_logfile(const char *logfile)
void alpm_option_set_usesyslog(unsigned short usesyslog)
{
- handle->usesyslog = usesyslog;
+ handle->usesyslog = usesyslog;
}
void alpm_option_add_noupgrade(char *pkg)
{
- handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg));
+ handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg));
}
void alpm_option_set_noupgrades(alpm_list_t *noupgrade)
@@ -201,7 +232,7 @@ void alpm_option_set_noupgrades(alpm_list_t *noupgrade)
void alpm_option_add_noextract(char *pkg)
{
- handle->noextract = alpm_list_add(handle->noextract, strdup(pkg));
+ handle->noextract = alpm_list_add(handle->noextract, strdup(pkg));
}
void alpm_option_set_noextracts(alpm_list_t *noextract)
{
@@ -211,7 +242,7 @@ void alpm_option_set_noextracts(alpm_list_t *noextract)
void SYMEXPORT alpm_option_add_ignorepkg(char *pkg)
{
- handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg));
+ handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg));
}
void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
{
@@ -221,7 +252,7 @@ void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
void alpm_option_add_holdpkg(char *pkg)
{
- handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg));
+ handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg));
}
void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs)
{
@@ -231,7 +262,7 @@ void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs)
void alpm_option_set_upgradedelay(time_t delay)
{
- handle->upgradedelay = delay;
+ handle->upgradedelay = delay;
}
void alpm_option_set_xfercommand(const char *cmd)
@@ -242,14 +273,14 @@ void alpm_option_set_xfercommand(const char *cmd)
void alpm_option_set_nopassiveftp(unsigned short nopasv)
{
- handle->nopassiveftp = nopasv;
+ handle->nopassiveftp = nopasv;
}
void alpm_option_set_chomp(unsigned short chomp) { handle->chomp = chomp; }
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: */
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 997c276f..bd75a370 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -69,7 +69,7 @@ extern pmhandle_t *handle;
#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);
#endif /* _ALPM_HANDLE_H */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 4b2350f8..3cd70dc0 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -206,10 +206,11 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
FREE(hash);
}
- if(!needbackup && trans->type == PM_TRANS_TYPE_UPGRADE) {
+ if(trans->type == PM_TRANS_TYPE_UPGRADE) {
/* check noupgrade */
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,28 +233,31 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
* explanation. */
if(alpm_list_find_str(trans->skip_remove, file)) {
_alpm_log(PM_LOG_DEBUG, _("%s is in trans->skip_remove, skipping removal"), file);
+ return;
} else if(needbackup) {
/* if the file is flagged, back it up to .pacsave */
if(!(trans->type == PM_TRANS_TYPE_UPGRADE)) {
/* if it was an upgrade, the file would be left alone because
* pacman_add() would handle it */
- if(!(trans->type & PM_TRANS_FLAG_NOSAVE)) {
+ if(!(trans->flags & PM_TRANS_FLAG_NOSAVE)) {
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s.pacsave", file);
rename(file, newpath);
_alpm_log(PM_LOG_WARNING, _("%s saved as %s"), file, newpath);
+ return;
+ } else {
+ _alpm_log(PM_LOG_DEBUG, _("transaction is set to NOSAVE, not backing up '%s'"), file);
}
}
- } else {
- _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 */
+ }
+ _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 */
- PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, (double)(percent * 100), list_count, (list_count - alpm_list_count(targ) + 1));
- ++(*position);
+ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, (double)(percent * 100), list_count, (list_count - alpm_list_count(targ) + 1));
+ ++(*position);
- if(unlink(file) == -1) {
- _alpm_log(PM_LOG_ERROR, _("cannot remove file %s: %s"), lp->data, strerror(errno));
- }
+ if(unlink(file) == -1) {
+ _alpm_log(PM_LOG_ERROR, _("cannot remove file %s: %s"), lp->data, strerror(errno));
}
}
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 26c3e43c..31c3b6a4 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -128,7 +128,7 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
/* check for "recommended" 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) {
+ for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DEPENDS); j; j = j->next) {
pmpkg_t *spkg = j->data;
for(k = spkg->replaces; k; k = k->next) {
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;
/* check for "recommended" 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_DEBUG, _("checking for package upgrades"));
@@ -229,19 +228,24 @@ 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 */
if(alpm_pkg_compare_versions(local, spkg)) {
- _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);
- if(dummy == NULL) {
- goto error;
- }
- sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
- if(sync == NULL) {
- FREEPKG(dummy);
- goto error;
+ 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)"),
+ 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);
+ if(dummy == NULL) {
+ goto error;
+ }
+ sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
+ if(sync == NULL) {
+ FREEPKG(dummy);
+ goto error;
+ }
+ trans->packages = alpm_list_add(trans->packages, sync);
}
- trans->packages = alpm_list_add(trans->packages, sync);
}
}
}
@@ -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
*/
-/* removed - use pkg_cmp all of the time
-static int ptr_cmp(const void *s1, const void *s2)
+static int syncpkg_cmp(const void *s1, const void *s2)
{
return(strcmp(((pmsyncpkg_t *)s1)->pkg->name, ((pmsyncpkg_t *)s2)->pkg->name));
-}*/
+}
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) {
pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages);
void *vpkg;
- _alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rmpkg);
- trans->packages = alpm_list_remove(trans->packages, rsync, pkg_cmp, &vpkg);
+ _alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rsync->pkg->name);
+ trans->packages = alpm_list_remove(trans->packages, rsync, syncpkg_cmp, &vpkg);
FREESYNC(vpkg);
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 */
void *vpkg;
_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);
}
} else {