diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2005-04-17 00:23:28 +0200 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2005-04-17 00:23:28 +0200 |
commit | 6e5bbdb5442df560d52739211e22beed6dfa6799 (patch) | |
tree | 66a4d9526ae7565aa07f3514427242b33a7fe8ed /lib/libalpm | |
parent | 36087bb392e0f045039cd9d51188d9eb7fe4d98b (diff) | |
download | pacman-6e5bbdb5442df560d52739211e22beed6dfa6799.tar.gz pacman-6e5bbdb5442df560d52739211e22beed6dfa6799.tar.xz |
- general cleanup
- added alpm_trans_sysupgrade() function
- relocated some defines
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.c | 90 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 21 | ||||
-rw-r--r-- | lib/libalpm/handle.h | 4 |
3 files changed, 57 insertions, 58 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 8afe73b4..1c85eafe 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -50,6 +50,9 @@ #include "handle.h" #include "alpm.h" +#define PM_LOCK "/tmp/pacman.lck" + + /* Globals */ pmhandle_t *handle = NULL; enum __pmerrno_t pm_errno; @@ -141,7 +144,7 @@ int alpm_get_option(unsigned char parm, long *data) * Databases */ -PM_DB *alpm_db_register(char *treename) +pmdb_t *alpm_db_register(char *treename) { pmdb_t *db; @@ -174,7 +177,7 @@ PM_DB *alpm_db_register(char *treename) return(db); } -int alpm_db_unregister(PM_DB *db) +int alpm_db_unregister(pmdb_t *db) { PMList *i; int found = 0; @@ -191,9 +194,7 @@ int alpm_db_unregister(PM_DB *db) for(i = handle->dbs_sync; i && !found; i = i->next) { if(db == i->data) { db_close(i->data); - i->data = NULL; - /* ORE - it should be _alpm_list_removed instead */ + handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, i); found = 1; } } @@ -282,7 +283,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts) return(0); } -PM_PKG *alpm_db_readpkg(PM_DB *db, char *name) +pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -292,7 +293,7 @@ PM_PKG *alpm_db_readpkg(PM_DB *db, char *name) return(db_get_pkgfromcache(db, name)); } -PM_LIST *alpm_db_getpkgcache(PM_DB *db) +PMList *alpm_db_getpkgcache(pmdb_t *db) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -301,7 +302,7 @@ PM_LIST *alpm_db_getpkgcache(PM_DB *db) return(db_get_pkgcache(db)); } -PM_GRP *alpm_db_readgrp(PM_DB *db, char *name) +pmgrp_t *alpm_db_readgrp(pmdb_t *db, char *name) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -311,7 +312,7 @@ PM_GRP *alpm_db_readgrp(PM_DB *db, char *name) return(db_get_grpfromcache(db, name)); } -PM_LIST *alpm_db_getgrpcache(PM_DB *db) +PMList *alpm_db_getgrpcache(pmdb_t *db) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -324,7 +325,7 @@ PM_LIST *alpm_db_getgrpcache(PM_DB *db) * Packages */ -void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) +void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm) { void *data = NULL; @@ -353,8 +354,8 @@ void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) case PM_PKG_REPLACES: case PM_PKG_MD5SUM: if(!(pkg->infolevel & INFRQ_DESC)) { - char target[PKG_NAME_LEN+PKG_VERSION_LEN]; - snprintf(target, PKG_NAME_LEN+PKG_VERSION_LEN, "%s-%s", pkg->name, pkg->version); + char target[(PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1]; + snprintf(target, (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1, "%s-%s", pkg->name, pkg->version); db_read(pkg->data, target, INFRQ_DESC, pkg); } break;*/ @@ -366,8 +367,8 @@ void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) case PM_PKG_CONFLICTS: case PM_PKG_PROVIDES: if(!(pkg->infolevel & INFRQ_DEPENDS)) { - char target[PKG_NAME_LEN+PKG_VERSION_LEN]; - snprintf(target, PKG_NAME_LEN+PKG_VERSION_LEN, "%s-%s", pkg->name, pkg->version); + char target[(PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1]; + snprintf(target, (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1, "%s-%s", pkg->name, pkg->version); db_read(pkg->data, target, INFRQ_DEPENDS, pkg); } break;*/ @@ -375,16 +376,16 @@ void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) case PM_PKG_FILES: case PM_PKG_BACKUP: if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_FILES)) { - char target[PKG_NAME_LEN+PKG_VERSION_LEN]; - snprintf(target, PKG_NAME_LEN+PKG_VERSION_LEN, "%s-%s", pkg->name, pkg->version); + char target[(PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1]; + snprintf(target, (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1, "%s-%s", pkg->name, pkg->version); db_read(pkg->data, target, INFRQ_FILES, pkg); } break; /* Scriptlet */ case PM_PKG_SCRIPLET: if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_SCRIPLET)) { - char target[PKG_NAME_LEN+PKG_VERSION_LEN]; - snprintf(target, PKG_NAME_LEN+PKG_VERSION_LEN, "%s-%s", pkg->name, pkg->version); + char target[(PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1]; + snprintf(target, (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1, "%s-%s", pkg->name, pkg->version); db_read(pkg->data, target, INFRQ_SCRIPLET, pkg); } break; @@ -413,7 +414,7 @@ void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) case PM_PKG_FILES: data = pkg->files; break; case PM_PKG_BACKUP: data = pkg->backup; break; case PM_PKG_SCRIPLET: data = (void *)(int)pkg->scriptlet; break; - case PM_PKG_DB: data = pkg->data; break; + case PM_PKG_DATA: data = pkg->data; break; default: data = NULL; break; @@ -422,7 +423,7 @@ void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm) return(data); } -int alpm_pkg_load(char *filename, PM_PKG **pkg) +int alpm_pkg_load(char *filename, pmpkg_t **pkg) { /* Sanity checks */ ASSERT(filename != NULL && strlen(filename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1)); @@ -437,14 +438,12 @@ int alpm_pkg_load(char *filename, PM_PKG **pkg) return(0); } -int alpm_pkg_free(PM_PKG *pkg) +void alpm_pkg_free(pmpkg_t *pkg) { - /* Sanity checks */ - ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - + if(pkg == NULL) { + return; + } pkg_free(pkg); - - return(0); } int alpm_pkg_vercmp(const char *ver1, const char *ver2) @@ -456,7 +455,7 @@ int alpm_pkg_vercmp(const char *ver1, const char *ver2) * Groups */ -void *alpm_grp_getinfo(PM_GRP *grp, unsigned char parm) +void *alpm_grp_getinfo(pmgrp_t *grp, unsigned char parm) { void *data = NULL; @@ -478,7 +477,7 @@ void *alpm_grp_getinfo(PM_GRP *grp, unsigned char parm) * Sync operations */ -void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm) +void *alpm_sync_getinfo(pmsyncpkg_t *sync, unsigned char parm) { void *data; @@ -487,9 +486,8 @@ void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm) switch(parm) { case PM_SYNC_TYPE: data = (void *)(int)sync->type; break; - case PM_SYNC_LOCALPKG: data = sync->lpkg; break; - case PM_SYNC_SYNCPKG: data = sync->spkg; break; - case PM_SYNC_REPLACES: data = sync->replaces; break; + case PM_SYNC_PKG: data = sync->pkg; break; + case PM_SYNC_DATA: data = sync->data; break; default: data = NULL; break; @@ -498,14 +496,6 @@ void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm) return(data); } -int alpm_sync_sysupgrade(PM_LIST **data) -{ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - - return(sync_sysupgrade(data)); -} - /* * Transactions */ @@ -548,6 +538,20 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb) return(trans_init(handle->trans, type, flags, cb)); } +int alpm_trans_sysupgrade() +{ + pmtrans_t *trans; + + ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + + trans = handle->trans; + ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); + ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1)); + ASSERT(trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_XXX, -1)); + + return(trans_sysupgrade(trans)); +} + int alpm_trans_addtarget(char *target) { pmtrans_t *trans; @@ -672,28 +676,28 @@ int alpm_logaction(char *fmt, ...) * Lists wrappers */ -PM_LIST *alpm_list_first(PM_LIST *list) +PMList *alpm_list_first(PMList *list) { ASSERT(list != NULL, return(NULL)); return(list); } -PM_LIST *alpm_list_next(PM_LIST *entry) +PMList *alpm_list_next(PMList *entry) { ASSERT(entry != NULL, return(NULL)); return(entry->next); } -void *alpm_list_getdata(PM_LIST *entry) +void *alpm_list_getdata(PMList *entry) { ASSERT(entry != NULL, return(NULL)); return(entry->data); } -int alpm_list_free(PM_LIST *entry) +int alpm_list_free(PMList *entry) { if(entry) { /* ORE diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 1cc0c791..82512a83 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -25,6 +25,11 @@ * Arch Linux Package Management library */ +#define PM_VERSION "0.1.0" + +#define PM_ROOT "/" +#define PM_DBPATH "var/lib/pacman" + #define PM_EXT_PKG ".pkg.tar.gz" #define PM_EXT_DB ".db.tar.gz" @@ -44,9 +49,6 @@ typedef struct __pmdepmissing_t PM_DEPMISS; * Library */ -/* Version */ -#define PM_VERSION "0.1.0" - int alpm_initialize(char *root); int alpm_release(); @@ -144,7 +146,7 @@ enum { /* Sciplet */ PM_PKG_SCRIPLET, /* Misc */ - PM_PKG_DB + PM_PKG_DATA }; /* reasons -- ie, why the package was installed */ @@ -153,7 +155,7 @@ enum { void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm); int alpm_pkg_load(char *filename, PM_PKG **pkg); -int alpm_pkg_free(PM_PKG *pkg); +void alpm_pkg_free(PM_PKG *pkg); int alpm_pkg_vercmp(const char *ver1, const char *ver2); /* @@ -181,15 +183,12 @@ enum { /* Info parameters */ enum { PM_SYNC_TYPE = 1, - PM_SYNC_LOCALPKG, - PM_SYNC_SYNCPKG, - PM_SYNC_REPLACES + PM_SYNC_PKG, + PM_SYNC_DATA }; void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm); -int alpm_sync_sysupgrade(PM_LIST **data); - /* * Transactions */ @@ -210,7 +209,6 @@ enum { #define PM_TRANS_FLAG_CASCADE 0x10 #define PM_TRANS_FLAG_RECURSE 0x20 #define PM_TRANS_FLAG_DBONLY 0x40 -#define PM_TRANS_FLAG_SYSUPG 0x80 /* Events */ enum { @@ -243,6 +241,7 @@ enum { void *alpm_trans_getinfo(unsigned char parm); int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb); +int alpm_trans_sysupgrade(); int alpm_trans_addtarget(char *target); int alpm_trans_prepare(PM_LIST **data); int alpm_trans_commit(); diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4fe3c3ce..55894d80 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -26,10 +26,6 @@ #include "trans.h" #include "alpm.h" -#define PM_ROOT "/" -#define PM_DBPATH "var/lib/pacman" -#define PM_LOCK "/tmp/pacman.lck" - typedef enum __pmaccess_t { PM_ACCESS_RO, PM_ACCESS_RW |