update: handle actual package updates outside of the library
This commit is contained in:
@ -8,21 +8,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct __lm_ctx_update_cb_data {
|
||||
lm_ctx_update_callback_t callback;
|
||||
lm_ctx_update_state_t state;
|
||||
void *data;
|
||||
};
|
||||
|
||||
bool __lm_ctx_update_callback(lm_ctx_t *ctx, lm_pkg_t *pkg, char *file, size_t current, size_t total, void *data){
|
||||
struct __lm_ctx_update_cb_data *cbdata = data;
|
||||
|
||||
if(NULL == cbdata->callback)
|
||||
return true;
|
||||
|
||||
return cbdata->callback(ctx, pkg, cbdata->state, file, current, total, cbdata->data);
|
||||
}
|
||||
|
||||
lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx){
|
||||
if(NULL == ctx){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
@ -46,6 +31,7 @@ lm_ctx_update_list_t *lm_ctx_update_list(lm_ctx_t *ctx){
|
||||
list->packages = malloc(sizeof(lm_pkg_t));
|
||||
else
|
||||
list->packages = realloc(list->packages, (list->count+1)*sizeof(lm_pkg_t));
|
||||
|
||||
lm_package_copy(&list->packages[list->count++], &cur);
|
||||
}
|
||||
|
||||
@ -62,8 +48,10 @@ lm_pkg_t *lm_ctx_update_list_next(lm_ctx_update_list_t *list){
|
||||
if(NULL == list->packages)
|
||||
return NULL;
|
||||
|
||||
if(NULL == list->cur)
|
||||
if(NULL == list->cur){
|
||||
list->cur = &list->packages[0];
|
||||
return list->cur;
|
||||
}
|
||||
|
||||
for(int i = 0; i < list->count-1; i++){
|
||||
if(list->cur != &list->packages[i])
|
||||
@ -91,34 +79,23 @@ void lm_ctx_update_list_free(lm_ctx_update_list_t *list){
|
||||
free(list);
|
||||
}
|
||||
|
||||
bool lm_ctx_update(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_update_callback_t callback, void *data){
|
||||
lm_pkg_t *lm_ctx_update(lm_ctx_t *ctx, lm_pkg_t *pkg){
|
||||
if(NULL == ctx || NULL == pkg){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct __lm_ctx_update_cb_data cbdata = {
|
||||
.state = UPDATE_REMOVE,
|
||||
.callback = callback,
|
||||
.data = data,
|
||||
};
|
||||
lm_pkg_t *new = NULL;
|
||||
|
||||
if((new = lm_ctx_pool_find(ctx, pkg->name, NULL)) == NULL){
|
||||
lm_error_set(LM_ERR_PkgNotFound);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(eq(new->version, pkg->version)){
|
||||
lm_error_set(LM_ERR_PkgUpToDate);
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!lm_ctx_remove(ctx, pkg, __lm_ctx_update_callback, &cbdata))
|
||||
return false; // error set by function
|
||||
|
||||
if(!lm_ctx_install(ctx, new, __lm_ctx_update_callback, &cbdata))
|
||||
return false; // error set by function
|
||||
|
||||
return true;
|
||||
return new;
|
||||
}
|
||||
|
@ -63,9 +63,15 @@ bool lm_package_is_same(lm_pkg_t *one, lm_pkg_t *two){
|
||||
bool lm_package_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
||||
lm_package_init(dst);
|
||||
|
||||
dst->name = strdup(src->name);
|
||||
dst->version = strdup(src->version);
|
||||
dst->desc = strdup(src->desc);
|
||||
if(NULL != src->name)
|
||||
dst->name = strdup(src->name);
|
||||
|
||||
if(NULL != src->version)
|
||||
dst->version = strdup(src->version);
|
||||
|
||||
if(NULL != src->desc)
|
||||
dst->desc = strdup(src->desc);
|
||||
|
||||
dst->size = src->size;
|
||||
dst->pool = src->pool;
|
||||
|
||||
|
@ -45,8 +45,12 @@ bool lm_package_path_copy(lm_pkg_t *dst, lm_pkg_t *src){
|
||||
return false;
|
||||
}
|
||||
|
||||
dst->paths.archive = strdup(src->paths.archive);
|
||||
dst->paths.signature = strdup(src->paths.signature);
|
||||
if(NULL != src->paths.archive)
|
||||
dst->paths.archive = strdup(src->paths.archive);
|
||||
|
||||
if(NULL != src->paths.signature)
|
||||
dst->paths.signature = strdup(src->paths.signature);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user