FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 05-11-2008, 05:02 PM
Dan McGee
 
Default 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.

Signed-off-by: Dan McGee <dan@archlinux.org>
---
lib/libalpm/be_files.c | 7 +++-
lib/libalpm/cache.c | 2 -
lib/libalpm/package.c | 92 ++++++++++++++++++++++++------------------------
lib/libalpm/package.h | 7 ++--
4 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 00e631e..7c5e32d 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -236,7 +236,12 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
/* TODO removed corrupt entry from the FS here */
_alpm_pkg_free(pkg);
} else {
- pkg->origin = PKG_FROM_CACHE;
+ /* TODO bad bad hack for now */
+ if(db == handle->db_local) {
+ pkg->origin = PKG_FROM_LOCALDB;
+ } else {
+ pkg->origin = PKG_FROM_SYNCDB;
+ }
pkg->origin_data.db = db;
}
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index bfc4fd9..ae9a22e 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -58,8 +58,6 @@ int _alpm_db_load_pkgcache(pmdb_t *db)
while((info = _alpm_db_scan(db, NULL)) != NULL) {
_alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'
",
alpm_pkg_get_name(info), db->treename);
- info->origin = PKG_FROM_CACHE;
- info->origin_data.db = db;
/* add to the collection */
db->pkgcache = alpm_list_add(db->pkgcache, info);
count++;
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 3989b76..d152b93 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_LOCALDB, RET_ERR(PM_ERR_PKG_INVALID, -1));

fpath = _alpm_filecache_find(alpm_pkg_get_filename(pkg));

@@ -121,7 +120,7 @@ const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}

@@ -136,7 +135,7 @@ const char SYMEXPORT *alpm_pkg_get_name(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_BASE)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_BASE)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_BASE);
}
return pkg->name;
@@ -150,7 +149,7 @@ const char SYMEXPORT *alpm_pkg_get_version(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_BASE)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_BASE)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_BASE);
}
return pkg->version;
@@ -164,7 +163,7 @@ const char SYMEXPORT *alpm_pkg_get_desc(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->desc;
@@ -178,7 +177,7 @@ const char SYMEXPORT *alpm_pkg_get_url(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->url;
@@ -192,7 +191,7 @@ time_t SYMEXPORT alpm_pkg_get_builddate(pmpkg_t *pkg)
ASSERT(handle != NULL, return(0));
ASSERT(pkg != NULL, return(0));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->builddate;
@@ -206,7 +205,7 @@ time_t SYMEXPORT alpm_pkg_get_installdate(pmpkg_t *pkg)
ASSERT(handle != NULL, return(0));
ASSERT(pkg != NULL, return(0));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->installdate;
@@ -220,7 +219,7 @@ const char SYMEXPORT *alpm_pkg_get_packager(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->packager;
@@ -234,7 +233,7 @@ const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->md5sum;
@@ -248,7 +247,7 @@ const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->arch;
@@ -262,7 +261,7 @@ unsigned long SYMEXPORT alpm_pkg_get_size(pmpkg_t *pkg)
ASSERT(handle != NULL, return(-1));
ASSERT(pkg != NULL, return(-1));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->size;
@@ -276,7 +275,7 @@ unsigned long SYMEXPORT alpm_pkg_get_isize(pmpkg_t *pkg)
ASSERT(handle != NULL, return(-1));
ASSERT(pkg != NULL, return(-1));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->isize;
@@ -290,7 +289,7 @@ pmpkgreason_t SYMEXPORT alpm_pkg_get_reason(pmpkg_t *pkg)
ASSERT(handle != NULL, return(-1));
ASSERT(pkg != NULL, return(-1));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->reason;
@@ -304,7 +303,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->licenses;
@@ -318,7 +317,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->groups;
@@ -332,7 +331,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_depends(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DEPENDS)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
}
return pkg->depends;
@@ -346,7 +345,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DEPENDS)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
}
return pkg->optdepends;
@@ -360,7 +359,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DEPENDS)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
}
return pkg->conflicts;
@@ -374,7 +373,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_provides(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DEPENDS)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
}
return pkg->provides;
@@ -388,7 +387,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DELTAS)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DELTAS)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DELTAS);
}
return pkg->deltas;
@@ -402,7 +401,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(pmpkg_t *pkg)
ASSERT(handle != NULL, return(NULL));
ASSERT(pkg != NULL, return(NULL));

- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
+ if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
return pkg->replaces;
@@ -416,7 +415,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_FILE && pkg->origin_data.db == handle->db_local
&& !(pkg->infolevel & INFRQ_FILES)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
}
@@ -431,7 +430,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_FILE && pkg->origin_data.db == handle->db_local
&& !(pkg->infolevel & INFRQ_FILES)) {
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
}
@@ -453,15 +452,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;
@@ -489,7 +480,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);
}

@@ -506,10 +506,10 @@ 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) {
ret = archive_read_data((struct archive*)fp, ptr, size);
+ } else {
+ ret = fread(ptr, 1, size, (FILE*)fp);
}
return(ret);
}
@@ -518,11 +518,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);
}
@@ -539,10 +539,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);
}
@@ -555,7 +555,7 @@ unsigned short 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);
}
@@ -809,7 +809,7 @@ int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)

ALPM_LOG_FUNC;

- if(pkg->origin == PKG_FROM_CACHE) {
+ if(pkg->origin != PKG_FROM_FILE) {
/* ensure we have the /desc file, which contains the 'force' option */
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
}
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 2e4ff31..6027021 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -29,8 +29,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 {
@@ -62,8 +63,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;
--
1.5.5.1


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 05-12-2008, 09:33 AM
Xavier
 
Default Allow local and sync db to be treated separately

On Sun, May 11, 2008 at 7:02 PM, Dan McGee <dan@archlinux.org> wrote:
>
> @@ -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_LOCALDB, RET_ERR(PM_ERR_PKG_INVALID, -1));
>

Hm, it is sync repositories and pkg->origin_data.db != handle->db_local,
so it should be SYNCDB and not LOCALDB, right?
However, I don't see why this function could not work with packages
from localdb. As long as it doesn't come from the file itself, it
should be fine. So I guess != PKG_FROM_FILE is fine, and the comment
could be changed.

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 05:18 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org