diff options
author | Dan McGee <dan@archlinux.org> | 2008-05-11 12:00:18 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2010-10-13 23:53:18 +1000 |
commit | d1126db1281596ba8ea960bfa963e86731d28b5e (patch) | |
tree | 4201eb0da47075c27b65e38eea4f4046a25861f4 /lib/libalpm | |
parent | 49176461a6b476e673e232075c95f07963750f74 (diff) |
Allow local and sync db to be treated separately
Implement this seemingly simple change in package.h:
typedef enum _pmpkgfrom_t {
- PKG_FROM_CACHE = 1,
- PKG_FROM_FILE
+ PKG_FROM_FILE = 1,
+ PKG_FROM_LOCALDB,
+ PKG_FROM_SYNCDB
} pmpkgfrom_t;
which requires flushing out several assumptions from around the codebase
with regards to usage of the PKG_FROM_CACHE value. Make some changes where
required to allow the switch, and now the correct value should be set (via a
crude hack) depending on whether a package was loaded as an entry in a local
db or a sync db.
This patch underwent some big rebasing from Allan and Dan.
Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/be_files.c | 6 | ||||
-rw-r--r-- | lib/libalpm/cache.c | 3 | ||||
-rw-r--r-- | lib/libalpm/package.c | 53 | ||||
-rw-r--r-- | lib/libalpm/package.h | 7 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 2 |
5 files changed, 37 insertions, 34 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 0f055e03..c0298049 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -415,7 +415,11 @@ int _alpm_db_populate(pmdb_t *db) _alpm_pkg_free(pkg); continue; } - pkg->origin = PKG_FROM_CACHE; + if(db == handle->db_local) { + pkg->origin = PKG_FROM_LOCALDB; + } else { + pkg->origin = PKG_FROM_SYNCDB; + } pkg->origin_data.db = db; /* add to the collection */ _alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n", diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index a9a7edd9..5126f3b1 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -120,9 +120,6 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg) _alpm_pkg_free(newpkg); return(-1); } - newpkg->origin = PKG_FROM_CACHE; - newpkg->origin_data.db = db; - newpkg->infolevel = INFRQ_BASE; _alpm_log(PM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n", alpm_pkg_get_name(newpkg), db->treename); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 8c572810..d30e6138 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -63,7 +63,7 @@ int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg) ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); /* Only free packages loaded in user space */ - if(pkg->origin != PKG_FROM_CACHE) { + if(pkg->origin == PKG_FROM_FILE) { _alpm_pkg_free(pkg); } @@ -83,8 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg) ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); /* We only inspect packages from sync repositories */ - ASSERT(pkg->origin == PKG_FROM_CACHE, RET_ERR(PM_ERR_PKG_INVALID, -1)); - ASSERT(pkg->origin_data.db != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1)); + ASSERT(pkg->origin == PKG_FROM_SYNCDB, RET_ERR(PM_ERR_PKG_INVALID, -1)); fpath = _alpm_filecache_find(alpm_pkg_get_filename(pkg)); @@ -105,7 +104,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg) ALPM_LOG_FUNC; \ ASSERT(handle != NULL, return(errret)); \ ASSERT(pkg != NULL, return(errret)); \ - if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & info)) { \ + if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \ _alpm_db_read(pkg->origin_data.db, pkg, info); \ } \ } while(0) @@ -250,7 +249,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_files(pmpkg_t *pkg) ASSERT(handle != NULL, return(NULL)); ASSERT(pkg != NULL, return(NULL)); - if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local + if(pkg->origin == PKG_FROM_LOCALDB && !(pkg->infolevel & INFRQ_FILES)) { _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES); } @@ -265,7 +264,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg) ASSERT(handle != NULL, return(NULL)); ASSERT(pkg != NULL, return(NULL)); - if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local + if(pkg->origin == PKG_FROM_LOCALDB && !(pkg->infolevel & INFRQ_FILES)) { _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES); } @@ -276,7 +275,7 @@ pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg) { /* Sanity checks */ ASSERT(pkg != NULL, return(NULL)); - ASSERT(pkg->origin == PKG_FROM_CACHE, return(NULL)); + ASSERT(pkg->origin != PKG_FROM_FILE, return(NULL)); return(pkg->origin_data.db); } @@ -296,15 +295,7 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg) ASSERT(handle != NULL, return(NULL)); ASSERT(pkg != NULL, return(NULL)); - if(pkg->origin == PKG_FROM_CACHE) { - char clfile[PATH_MAX]; - snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog", - alpm_option_get_dbpath(), - alpm_db_get_name(handle->db_local), - alpm_pkg_get_name(pkg), - alpm_pkg_get_version(pkg)); - return fopen(clfile, "r"); - } else if(pkg->origin == PKG_FROM_FILE) { + if(pkg->origin == PKG_FROM_FILE) { struct archive *archive = NULL; struct archive_entry *entry; const char *pkgfile = pkg->origin_data.file; @@ -331,7 +322,16 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg) /* we didn't find a changelog */ archive_read_finish(archive); errno = ENOENT; + } else { + char clfile[PATH_MAX]; + snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog", + alpm_option_get_dbpath(), + alpm_db_get_name(handle->db_local), + alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); + return fopen(clfile, "r"); } + return(NULL); } @@ -351,9 +351,8 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const pmpkg_t *pkg, const void *fp) { size_t ret = 0; - if(pkg->origin == PKG_FROM_CACHE) { - ret = fread(ptr, 1, size, (FILE*)fp); - } else if(pkg->origin == PKG_FROM_FILE) { + + if(pkg->origin == PKG_FROM_FILE) { ssize_t sret = archive_read_data((struct archive*)fp, ptr, size); /* Report error (negative values) */ if(sret < 0) { @@ -362,6 +361,8 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, } else { ret = (size_t)sret; } + } else { + ret = fread(ptr, 1, size, (FILE*)fp); } return(ret); } @@ -370,11 +371,11 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, int SYMEXPORT alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp) { int ret = 0; - if(pkg->origin == PKG_FROM_CACHE) { - ret = feof((FILE*)fp); - } else if(pkg->origin == PKG_FROM_FILE) { + if(pkg->origin == PKG_FROM_FILE) { // note: this doesn't quite work, no feof in libarchive ret = archive_read_data((struct archive*)fp, NULL, 0); + } else { + ret = feof((FILE*)fp); } return(ret); } @@ -391,10 +392,10 @@ int SYMEXPORT alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp) int SYMEXPORT alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp) { int ret = 0; - if(pkg->origin == PKG_FROM_CACHE) { - ret = fclose((FILE*)fp); - } else if(pkg->origin == PKG_FROM_FILE) { + if(pkg->origin == PKG_FROM_FILE) { ret = archive_read_finish((struct archive *)fp); + } else { + ret = fclose((FILE*)fp); } return(ret); } @@ -407,7 +408,7 @@ int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg) ASSERT(handle != NULL, return(-1)); ASSERT(pkg != NULL, return(-1)); - if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local + if(pkg->origin == PKG_FROM_LOCALDB && !(pkg->infolevel & INFRQ_SCRIPTLET)) { _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET); } diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 14f81f92..daff9717 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -31,8 +31,9 @@ #include "db.h" typedef enum _pmpkgfrom_t { - PKG_FROM_CACHE = 1, - PKG_FROM_FILE + PKG_FROM_FILE = 1, + PKG_FROM_LOCALDB, + PKG_FROM_SYNCDB } pmpkgfrom_t; struct __pmpkg_t { @@ -67,8 +68,8 @@ struct __pmpkg_t { /* internal */ pmpkgfrom_t origin; /* Replaced 'void *data' with this union as follows: - origin == PKG_FROM_CACHE, use pkg->origin_data.db origin == PKG_FROM_FILE, use pkg->origin_data.file + origin == PKG_FROM_*DB, use pkg->origin_data.db */ union { pmdb_t *db; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index f8193962..9e155b6e 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -832,7 +832,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) for(j = trans->add; j; j = j->next) { pmpkg_t *spkg = j->data; - if(spkg->origin == PKG_FROM_CACHE && current == spkg->origin_data.db) { + if(spkg->origin != PKG_FROM_FILE && current == spkg->origin_data.db) { const char *fname = NULL; fname = alpm_pkg_get_filename(spkg); |