diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2005-04-23 17:18:31 +0000 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2005-04-23 17:18:31 +0000 |
commit | e2b474b1309594c610a2cf25f35b349575d88223 (patch) | |
tree | 47e19d9745c290cca2b5a8fb3bee1d6150a41b59 /lib/libalpm/cache.c | |
parent | e56980597b90b5107f577c25b25c1a0818d61d7a (diff) | |
download | pacman-e2b474b1309594c610a2cf25f35b349575d88223.tar.xz |
rework the cache handling to avoid as much as possible calls to db_scan()
Diffstat (limited to 'lib/libalpm/cache.c')
-rw-r--r-- | lib/libalpm/cache.c | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index a44842d6..3e1c230a 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -64,7 +64,7 @@ int db_load_pkgcache(pmdb_t *db) void db_free_pkgcache(pmdb_t *db) { - if(db == NULL || db->pkgcache == NULL) { + if(db == NULL) { return; } @@ -88,6 +88,57 @@ PMList *db_get_pkgcache(pmdb_t *db) return(db->pkgcache); } +int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg) +{ + pmpkg_t *newpkg; + + _alpm_log(PM_LOG_FUNCTION, "[db_add_pkgincache] called"); + + if(db == NULL || pkg == NULL) { + return(-1); + } + + newpkg = pkg_dup(pkg); + if(newpkg == NULL) { + return(-1); + } + db->pkgcache = pm_list_add_sorted(db->pkgcache, newpkg, pkg_cmp); + + db_free_grpcache(db); + + return(0); +} + +int db_remove_pkgfromcache(pmdb_t *db, char *name) +{ + PMList *i; + int found = 0; + + if(db == NULL || name == NULL || strlen(name) == 0) { + return(-1); + } + + _alpm_log(PM_LOG_FUNCTION, "[db_remove_pkgfromcache] called"); + + for(i = db->pkgcache; i && !found; i = i->next) { + if(strcmp(((pmpkg_t *)i->data)->name, name) == 0) { + _alpm_log(PM_LOG_DEBUG, "removing entry %s from \"%s\" cache", name, db->treename); + db->pkgcache = _alpm_list_remove(db->pkgcache, i); + /* ORE + MLK: list_remove() does not free properly an entry from a packages list */ + found = 1; + } + } + + if(!found) { + return(-1); + } + + db_free_grpcache(db); + + return(0); +} + pmpkg_t *db_get_pkgfromcache(pmdb_t *db, char *target) { PMList *i; @@ -158,7 +209,7 @@ void db_free_grpcache(pmdb_t *db) { PMList *lg; - if(db == NULL || db->grpcache == NULL) { + if(db == NULL) { return; } |