new: ctx package list functions
This commit is contained in:
parent
bb1f5a61b2
commit
73a1f997e6
@ -14,6 +14,13 @@ typedef struct lm_ctx {
|
||||
const char *version; // libmp version (read-only)
|
||||
} lm_ctx_t;
|
||||
|
||||
typedef struct lm_ctx_list {
|
||||
lm_pool_t *head;
|
||||
lm_pool_t *pool;
|
||||
lm_pkg_t *pkg;
|
||||
ssize_t count;
|
||||
} lm_ctx_list_t;
|
||||
|
||||
typedef struct lm_ctx_resolve_list {
|
||||
lm_pkg_t *resolving;
|
||||
lm_pkg_t *packages;
|
||||
@ -62,6 +69,10 @@ void lm_ctx_free(lm_ctx_t *ctx);
|
||||
/* ####################
|
||||
## main fucntions ##
|
||||
#################### */
|
||||
lm_ctx_list_t *lm_ctx_list(lm_ctx_t *ctx, lm_ctx_list_t *list); // returns the state of package list
|
||||
lm_pkg_t *lm_ctx_list_next(lm_ctx_list_t *list); // returns the next package in the list
|
||||
void lm_ctx_list_free(lm_ctx_list_t *list); // frees the package list state
|
||||
|
||||
lm_ctx_resolve_list_t *lm_ctx_resolve(
|
||||
lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_resolve_list_t *list); // resolves a package and returns a list of packages
|
||||
lm_pkg_t *lm_ctx_resolve_next(lm_ctx_resolve_list_t *list); // returns the next package in the list
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-08-04 15:24+0300\n"
|
||||
"POT-Creation-Date: 2024-08-04 18:59+0300\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -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));
|
||||
}
|
@ -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;
|
||||
@ -123,10 +128,15 @@ 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;
|
||||
@ -138,4 +148,6 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac
|
||||
}
|
||||
|
||||
return loaded_count;
|
||||
fail:
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user