diff options
author | Dan McGee <dan@archlinux.org> | 2011-06-03 22:24:01 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-06-07 18:37:05 +0200 |
commit | fb4b422fc4567238332050b9a6c8c1cac2a8f091 (patch) | |
tree | 047457f6cadf5493406b0ca4fa8c60230481d92d /lib/libalpm/handle.c | |
parent | 992fa50dfd4faba93e37364bded015ea04d1fe15 (diff) | |
download | pacman-fb4b422fc4567238332050b9a6c8c1cac2a8f091.tar.gz pacman-fb4b422fc4567238332050b9a6c8c1cac2a8f091.tar.xz |
New signatures for alpm initialize and release
These new method signatures return and take handle objects to operate on
so we can move away from the idea of one global handle in the API. There
is also another important change and that deals with the setting of root
and dbpaths. These are now done at initialization time instead of using
setter methods. This allows the library to operate more safely knowing
that paths won't change underneath it.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/handle.c')
-rw-r--r-- | lib/libalpm/handle.c | 44 |
1 files changed, 4 insertions, 40 deletions
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index ccd13f11..80ad5601 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -313,7 +313,7 @@ static char *canonicalize_path(const char *path) { return new_path; } -int _alpm_set_directory_option(const char *value, +enum _pmerrno_t _alpm_set_directory_option(const char *value, char **storage, int must_exist) { struct stat st; @@ -322,19 +322,16 @@ int _alpm_set_directory_option(const char *value, path = value; if(!path) { - pm_errno = PM_ERR_WRONG_ARGS; - return -1; + return PM_ERR_WRONG_ARGS; } if(must_exist) { if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { - pm_errno = PM_ERR_NOT_A_DIR; - return -1; + return PM_ERR_NOT_A_DIR; } real = calloc(PATH_MAX + 1, sizeof(char)); if(!realpath(path, real)) { free(real); - pm_errno = PM_ERR_NOT_A_DIR; - return -1; + return PM_ERR_NOT_A_DIR; } path = real; } @@ -347,39 +344,6 @@ int _alpm_set_directory_option(const char *value, return 0; } -int SYMEXPORT alpm_option_set_root(const char *root) -{ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - - if(_alpm_set_directory_option(root, &(handle->root), 1)) { - return -1; - } - _alpm_log(PM_LOG_DEBUG, "option 'root' = %s\n", handle->root); - return 0; -} - -int SYMEXPORT alpm_option_set_dbpath(const char *dbpath) -{ - const char *lf = "db.lck"; - size_t lockfilelen; - - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - - if(_alpm_set_directory_option(dbpath, &(handle->dbpath), 1)) { - return -1; - } - _alpm_log(PM_LOG_DEBUG, "option 'dbpath' = %s\n", handle->dbpath); - - if(handle->lockfile) { - FREE(handle->lockfile); - } - lockfilelen = strlen(handle->dbpath) + strlen(lf) + 1; - handle->lockfile = calloc(lockfilelen, sizeof(char)); - snprintf(handle->lockfile, lockfilelen, "%s%s", handle->dbpath, lf); - _alpm_log(PM_LOG_DEBUG, "option 'lockfile' = %s\n", handle->lockfile); - return 0; -} - int SYMEXPORT alpm_option_add_cachedir(const char *cachedir) { char *newcachedir; |