new: ctx package list functions
This commit is contained in:
@ -102,5 +102,6 @@ void lm_ctx_free(lm_ctx_t *ctx) {
|
||||
lm_database_free(ctx->db);
|
||||
|
||||
lm_error_clear();
|
||||
bzero(ctx, sizeof(lm_ctx_t));
|
||||
return;
|
||||
}
|
||||
|
60
src/ctx/list.c
Normal file
60
src/ctx/list.c
Normal file
@ -0,0 +1,60 @@
|
||||
#include "../../include/package.h"
|
||||
#include "../../include/error.h"
|
||||
#include "../../include/ctx.h"
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
lm_ctx_list_t *lm_ctx_list(lm_ctx_t *ctx, lm_ctx_list_t *list){
|
||||
if(NULL == ctx || NULL == list){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->pool = ctx->pools;
|
||||
list->head = ctx->pools;
|
||||
list->pkg = NULL;
|
||||
list->count = 0;
|
||||
|
||||
while(NULL != list->pool){
|
||||
list->pkg = list->pool->pkg;
|
||||
while(NULL != list->pkg){
|
||||
list->count++;
|
||||
list->pkg = list->pkg->next;
|
||||
}
|
||||
list->pool = list->pool->next;
|
||||
}
|
||||
|
||||
list->pool = NULL;
|
||||
list->pkg = NULL;
|
||||
return list;
|
||||
}
|
||||
|
||||
lm_pkg_t *lm_ctx_list_next(lm_ctx_list_t *list){
|
||||
if(NULL == list){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(NULL == list->pool || NULL == list->pkg){
|
||||
if((list->pool = list->head) != NULL)
|
||||
list->pkg = list->pool->pkg;
|
||||
return list->pkg;
|
||||
}
|
||||
|
||||
if((list->pkg = list->pkg->next) && NULL == list->pkg){
|
||||
if((list->pool = list->pool->next) != NULL)
|
||||
list->pkg = list->pool->pkg;
|
||||
return list->pkg;
|
||||
}
|
||||
|
||||
return list->pkg;
|
||||
}
|
||||
|
||||
void lm_ctx_list_free(lm_ctx_list_t *list){
|
||||
if(NULL == list){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return;
|
||||
}
|
||||
|
||||
bzero(list, sizeof(lm_ctx_list_t));
|
||||
}
|
@ -57,12 +57,12 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
|
||||
}
|
||||
|
||||
if(!do_update && !lm_pool_info_load(cur)){
|
||||
pdebug(__func__, "(%s) failed to load info: %s", cur->name, lm_strerror());
|
||||
pdebug(__func__, "(%s) failed to load info: %s", cur->name, lm_strerror());
|
||||
goto next_info;
|
||||
}
|
||||
|
||||
else if(do_update && !lm_pool_info_download(cur, __lm_ctx_sync_callback, &cbdata)) {
|
||||
pdebug(__func__, "(%s) failed to update info: %s", cur->name, lm_strerror());
|
||||
pdebug(__func__, "(%s) failed to update info: %s", cur->name, lm_strerror());
|
||||
goto next_info;
|
||||
}
|
||||
|
||||
@ -70,10 +70,15 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
|
||||
status = true;
|
||||
|
||||
next_info:
|
||||
if(NULL != callback && status)
|
||||
callback(ctx, cur, SYNC_INFO_SUCCESS, 0, 0, data);
|
||||
else if(NULL != callback && !status)
|
||||
callback(ctx, cur, SYNC_INFO_FAIL, 0, 0, data);
|
||||
if(NULL != callback && status){
|
||||
if(!callback(ctx, cur, SYNC_INFO_SUCCESS, 0, 0, data))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
else if(NULL != callback && !status){
|
||||
if(!callback(ctx, cur, SYNC_INFO_FAIL, 0, 0, data))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(status)
|
||||
cur->loaded = true;
|
||||
@ -107,12 +112,12 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
|
||||
}
|
||||
|
||||
if(!do_update && !lm_pool_list_load(cur, tempdir)){
|
||||
pdebug(__func__, "(%s) failed to load list: %s", cur->name, lm_strerror());
|
||||
pdebug(__func__, "(%s) failed to load list: %s", cur->name, lm_strerror());
|
||||
goto next_list;
|
||||
}
|
||||
|
||||
else if(do_update && !lm_pool_list_download(cur, tempdir, __lm_ctx_sync_callback, &cbdata)) {
|
||||
pdebug(__func__, "(%s) failed to update list: %s", cur->name, lm_strerror());
|
||||
pdebug(__func__, "(%s) failed to update list: %s", cur->name, lm_strerror());
|
||||
goto next_list;
|
||||
}
|
||||
|
||||
@ -123,19 +128,26 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
|
||||
free(tempdir);
|
||||
tempdir = NULL;
|
||||
|
||||
if(NULL != callback && status)
|
||||
callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data);
|
||||
else if(NULL != callback && !status)
|
||||
callback(ctx, cur, SYNC_LIST_FAIL, 0, 0, data);
|
||||
if(NULL != callback && status){
|
||||
if(!callback(ctx, cur, SYNC_LIST_SUCCESS, 0, 0, data))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
else if(NULL != callback && !status){
|
||||
if(!callback(ctx, cur, SYNC_LIST_FAIL, 0, 0, data))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(!status)
|
||||
cur->loaded = false;
|
||||
else
|
||||
loaded_count++;
|
||||
|
||||
|
||||
status = false;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
return loaded_count;
|
||||
fail:
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user