[pacman-dev] Move the cache stuff where it should be
Xavier
shiningxc at gmail.com
Mon May 12 07:54:37 EDT 2008
http://code.toofishes.net/gitweb.cgi?p=pacman.git;a=commitdiff;h=4bef7544e116a681e9de180c3e17f457491b0d78
This stuff still requires fixing, right? I see these functions are now
declared in db.h, but we probably need generic functions here.
So the names are wrong. Maybe we could just rename them with :
s/cache/list or something.
Actually, it seems like we mostly need get_pkglist and free_pkglist.
And same for grouplist.
I don't know why we need to handle add_pkgincache and
remove_pkgfromcache manually.
These are called just after db_write and db_remove respectively. So
the implementation of these two db functions in the cache backend
could handle the cache themselves.
Hm well, just after writing this, I see there is a problem with the
db_update code :
/* remove the old dir */
_alpm_log(PM_LOG_DEBUG, "flushing database %s\n", db->path);
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
pmpkg_t *pkg = lp->data;
if(pkg && _alpm_db_remove(db, pkg) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not remove database entry
%s%s\n"), db->treename,
alpm_pkg_get_name(pkg));
RET_ERR(PM_ERR_DB_REMOVE, -1);
}
}
/* Cache needs to be rebuilt */
_alpm_db_free_pkgcache(db);
I remember there was the same problem with db_unregister /
db_unregister_all. We have to walk through the list and remove its
items one by one. I am still not sure how to do that correctly in C.
But it reminds me of the java Iterator interface where this is
possible:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Iterator.html
while(it.hasnext()) {
it.next();
it.remove();
}
Well, I don't know, but imo it would be better if the rest of libalpm
code didn't have to deal with this cache stuff at all.
More information about the pacman-dev
mailing list