mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
Improve cachedir removal and error handling
* Check the return value of canonicalize_path() for non-NULL * Use ASSERT and RET_ERR as appropriate * Make remove_cachedir() use same path munge logic as add_cachedir() Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
83071f579c
commit
36d98b3919
@ -276,6 +276,9 @@ enum _pmerrno_t _alpm_set_directory_option(const char *value,
|
|||||||
FREE(*storage);
|
FREE(*storage);
|
||||||
}
|
}
|
||||||
*storage = canonicalize_path(path);
|
*storage = canonicalize_path(path);
|
||||||
|
if(!*storage) {
|
||||||
|
return PM_ERR_MEMORY;
|
||||||
|
}
|
||||||
free(real);
|
free(real);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -285,14 +288,14 @@ int SYMEXPORT alpm_option_add_cachedir(pmhandle_t *handle, const char *cachedir)
|
|||||||
char *newcachedir;
|
char *newcachedir;
|
||||||
|
|
||||||
CHECK_HANDLE(handle, return -1);
|
CHECK_HANDLE(handle, return -1);
|
||||||
if(!cachedir) {
|
ASSERT(cachedir != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
|
||||||
handle->pm_errno = PM_ERR_WRONG_ARGS;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
/* don't stat the cachedir yet, as it may not even be needed. we can
|
/* don't stat the cachedir yet, as it may not even be needed. we can
|
||||||
* fail later if it is needed and the path is invalid. */
|
* fail later if it is needed and the path is invalid. */
|
||||||
|
|
||||||
newcachedir = canonicalize_path(cachedir);
|
newcachedir = canonicalize_path(cachedir);
|
||||||
|
if(!newcachedir) {
|
||||||
|
RET_ERR(handle, PM_ERR_MEMORY, -1);
|
||||||
|
}
|
||||||
handle->cachedirs = alpm_list_add(handle->cachedirs, newcachedir);
|
handle->cachedirs = alpm_list_add(handle->cachedirs, newcachedir);
|
||||||
_alpm_log(handle, PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir);
|
_alpm_log(handle, PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir);
|
||||||
return 0;
|
return 0;
|
||||||
@ -318,16 +321,13 @@ int SYMEXPORT alpm_option_remove_cachedir(pmhandle_t *handle, const char *cached
|
|||||||
{
|
{
|
||||||
char *vdata = NULL;
|
char *vdata = NULL;
|
||||||
char *newcachedir;
|
char *newcachedir;
|
||||||
size_t cachedirlen;
|
|
||||||
CHECK_HANDLE(handle, return -1);
|
CHECK_HANDLE(handle, return -1);
|
||||||
/* verify cachedir ends in a '/' */
|
ASSERT(cachedir != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
|
||||||
cachedirlen = strlen(cachedir);
|
|
||||||
if(cachedir[cachedirlen-1] != '/') {
|
newcachedir = canonicalize_path(cachedir);
|
||||||
cachedirlen += 1;
|
if(!newcachedir) {
|
||||||
|
RET_ERR(handle, PM_ERR_MEMORY, -1);
|
||||||
}
|
}
|
||||||
CALLOC(newcachedir, cachedirlen + 1, sizeof(char), return 0);
|
|
||||||
strncpy(newcachedir, cachedir, cachedirlen);
|
|
||||||
newcachedir[cachedirlen-1] = '/';
|
|
||||||
handle->cachedirs = alpm_list_remove_str(handle->cachedirs, newcachedir, &vdata);
|
handle->cachedirs = alpm_list_remove_str(handle->cachedirs, newcachedir, &vdata);
|
||||||
FREE(newcachedir);
|
FREE(newcachedir);
|
||||||
if(vdata != NULL) {
|
if(vdata != NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user