diff options
Diffstat (limited to 'lib/libalpm/alpm.c')
-rw-r--r-- | lib/libalpm/alpm.c | 94 |
1 files changed, 23 insertions, 71 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 95264831..9702ad95 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -100,7 +100,7 @@ int alpm_initialize(char *root) */ int alpm_release() { - PMList *i; + pmlist_t *i; ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); @@ -166,69 +166,17 @@ int alpm_get_option(unsigned char parm, long *data) /** Register a package database * @param treename the name of the repository - * @param callback a function to be called upon new database creation * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -pmdb_t *alpm_db_register(char *treename, alpm_cb_db_register callback) +pmdb_t *alpm_db_register(char *treename) { - struct stat buf; - pmdb_t *db; - char path[PATH_MAX]; - /* Sanity checks */ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL)); ASSERT(treename != NULL && strlen(treename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, NULL)); /* Do not register a database if a transaction is on-going */ ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL)); - if(strcmp(treename, "local") == 0) { - if(handle->db_local != NULL) { - _alpm_log(PM_LOG_WARNING, _("attempt to re-register the 'local' DB\n")); - RET_ERR(PM_ERR_DB_NOT_NULL, NULL); - } - } else { - PMList *i; - for(i = handle->dbs_sync; i; i = i->next) { - pmdb_t *sdb = i->data; - if(strcmp(treename, sdb->treename) == 0) { - _alpm_log(PM_LOG_DEBUG, _("attempt to re-register the '%s' databse, using existing\n"), sdb->treename); - return sdb; - } - } - } - - _alpm_log(PM_LOG_FLOW1, _("registering database '%s'"), treename); - - /* make sure the database directory exists */ - snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename); - if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { - _alpm_log(PM_LOG_FLOW1, _("database directory '%s' does not exist -- try creating it"), path); - if(_alpm_makepath(path) != 0) { - RET_ERR(PM_ERR_SYSTEM, NULL); - } - } - - db = _alpm_db_new(handle->root, handle->dbpath, treename); - if(db == NULL) { - RET_ERR(PM_ERR_DB_CREATE, NULL); - } - - _alpm_log(PM_LOG_DEBUG, _("opening database '%s'"), db->treename); - if(_alpm_db_open(db) == -1) { - _alpm_db_free(db); - RET_ERR(PM_ERR_DB_OPEN, NULL); - } - - /* Only call callback on NEW registration. */ - if(callback) callback(treename, db); - - if(strcmp(treename, "local") == 0) { - handle->db_local = db; - } else { - handle->dbs_sync = _alpm_list_add(handle->dbs_sync, db); - } - - return(db); + return(_alpm_db_register(treename, NULL)); } /** Unregister a package database @@ -324,7 +272,7 @@ int alpm_db_setserver(pmdb_t *db, char *url) found = 1; } } else { - PMList *i; + pmlist_t *i; for(i = handle->dbs_sync; i && !found; i = i->next) { pmdb_t *sdb = i->data; if(strcmp(db->treename, sdb->treename) == 0) { @@ -361,9 +309,9 @@ int alpm_db_setserver(pmdb_t *db, char *url) */ int alpm_db_update(int force, PM_DB *db) { - PMList *lp; + pmlist_t *lp; char path[PATH_MAX]; - PMList *files = NULL; + pmlist_t *files = NULL; char newmtime[16] = ""; char lastupdate[16] = ""; int ret; @@ -456,7 +404,7 @@ pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name) * @param db pointer to the package database to get the package from * @return the list of packages on success, NULL on error */ -PMList *alpm_db_getpkgcache(pmdb_t *db) +pmlist_t *alpm_db_getpkgcache(pmdb_t *db) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -470,7 +418,7 @@ PMList *alpm_db_getpkgcache(pmdb_t *db) * @param name name of the package * @return the list of packages on success, NULL on error */ -PMList *alpm_db_whatprovides(pmdb_t *db, char *name) +pmlist_t *alpm_db_whatprovides(pmdb_t *db, char *name) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -499,7 +447,7 @@ pmgrp_t *alpm_db_readgrp(pmdb_t *db, char *name) * @param db pointer to the package database to get the group from * @return the list of groups on success, NULL on error */ -PMList *alpm_db_getgrpcache(pmdb_t *db) +pmlist_t *alpm_db_getgrpcache(pmdb_t *db) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -624,6 +572,8 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm) */ int alpm_pkg_load(char *filename, pmpkg_t **pkg) { + _alpm_log(PM_LOG_FUNCTION, "enter alpm_pkg_load"); + /* Sanity checks */ ASSERT(filename != NULL && strlen(filename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); @@ -643,6 +593,8 @@ int alpm_pkg_load(char *filename, pmpkg_t **pkg) */ int alpm_pkg_free(pmpkg_t *pkg) { + _alpm_log(PM_LOG_FUNCTION, "enter alpm_pkg_free"); + ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); /* Only free packages loaded in user space */ @@ -822,7 +774,7 @@ void *alpm_sync_getinfo(pmsyncpkg_t *sync, unsigned char parm) * @param db pointer to the package database to search in * @return the list of packages on success, NULL on error */ -PMList *alpm_db_search(pmdb_t *db) +pmlist_t *alpm_db_search(pmdb_t *db) { /* Sanity checks */ ASSERT(handle != NULL, return(NULL)); @@ -940,7 +892,7 @@ int alpm_trans_addtarget(char *target) * of an error can be dumped (ie. list of conflicting files) * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int alpm_trans_prepare(PMList **data) +int alpm_trans_prepare(pmlist_t **data) { /* Sanity checks */ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); @@ -957,7 +909,7 @@ int alpm_trans_prepare(PMList **data) * of an error can be dumped (ie. list of conflicting files) * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int alpm_trans_commit(PMList **data) +int alpm_trans_commit(pmlist_t **data) { /* Sanity checks */ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); @@ -1122,7 +1074,7 @@ int alpm_logaction(char *fmt, ...) * @param list the list * @return the first element */ -PMList *alpm_list_first(PMList *list) +pmlist_t *alpm_list_first(pmlist_t *list) { return(list); } @@ -1131,7 +1083,7 @@ PMList *alpm_list_first(PMList *list) * @param entry the list entry * @return the next element on success, NULL on error */ -PMList *alpm_list_next(PMList *entry) +pmlist_t *alpm_list_next(pmlist_t *entry) { ASSERT(entry != NULL, return(NULL)); @@ -1142,7 +1094,7 @@ PMList *alpm_list_next(PMList *entry) * @param entry the list entry * @return the data on success, NULL on error */ -void *alpm_list_getdata(PMList *entry) +void *alpm_list_getdata(pmlist_t *entry) { ASSERT(entry != NULL, return(NULL)); @@ -1153,7 +1105,7 @@ void *alpm_list_getdata(PMList *entry) * @param entry list to free * @return 0 on success, -1 on error */ -int alpm_list_free(PMList *entry) +int alpm_list_free(pmlist_t *entry) { ASSERT(entry != NULL, return(-1)); @@ -1166,7 +1118,7 @@ int alpm_list_free(PMList *entry) * @param list the list to count * @return number of entries on success, NULL on error */ -int alpm_list_count(PMList *list) +int alpm_list_count(pmlist_t *list) { ASSERT(list != NULL, return(-1)); @@ -1235,7 +1187,7 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this if(this_section != NULL && strlen(this_section) > 0) { strncpy(section, this_section, min(255, strlen(this_section))); - db = alpm_db_register(section, callback); + db = _alpm_db_register(section, callback); } while(fgets(line, PATH_MAX, fp)) { @@ -1258,7 +1210,7 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this RET_ERR(PM_ERR_CONF_LOCAL, -1); } if(strcmp(section, "options")) { - db = alpm_db_register(section, callback); + db = _alpm_db_register(section, callback); if(db == NULL) { /* pm_errno is set by alpm_db_register */ return(-1); |