update: new examples
This commit is contained in:
@ -1,22 +0,0 @@
|
||||
#include "../../include/error.h"
|
||||
#include "../../include/pool.h"
|
||||
#include "../../include/ctx.h"
|
||||
|
||||
lm_pkg_t *lm_ctx_find(lm_ctx_t *ctx, char *name, char *version){
|
||||
if(NULL == ctx || (NULL == name && NULL == version)){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lm_pool_t *cur = ctx->pools;
|
||||
lm_pkg_t *found = NULL;
|
||||
while(cur != NULL){
|
||||
if((found = lm_pool_package_find(cur, name, version)) != NULL)
|
||||
break;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if(NULL == found)
|
||||
lm_error_set(LM_ERR_PkgNotFound);
|
||||
return found;
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <archive.h>
|
||||
#include <archive_entry.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
@ -242,6 +243,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call
|
||||
goto end;
|
||||
}
|
||||
|
||||
// TODO: run install script
|
||||
|
||||
ret = true;
|
||||
end:
|
||||
free(line);
|
||||
@ -255,5 +258,7 @@ end:
|
||||
lm_database_files_del(ctx->db, pkg);
|
||||
}
|
||||
|
||||
unlink(pkg->paths.archive);
|
||||
unlink(pkg->paths.signature);
|
||||
return ret;
|
||||
}
|
||||
|
@ -7,6 +7,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
lm_pkg_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name, char *version){
|
||||
if(NULL == ctx || (NULL == name && NULL == version)){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lm_pool_t *cur = ctx->pools;
|
||||
lm_pkg_t *found = NULL;
|
||||
|
||||
while(cur != NULL){
|
||||
if((found = lm_pool_package_find(cur, name, version)) != NULL)
|
||||
break;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
if(NULL == found)
|
||||
lm_error_set(LM_ERR_PkgNotFound);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
lm_pool_t *lm_ctx_pool_add(lm_ctx_t *ctx, char *name, char *url) {
|
||||
if(NULL == name){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
@ -57,7 +78,7 @@ void lm_ctx_pool_clear(lm_ctx_t *ctx) {
|
||||
ctx->pools = NULL;
|
||||
}
|
||||
|
||||
lm_pool_t *lm_ctx_pool_find(lm_ctx_t *ctx, char *name) {
|
||||
lm_pool_t *lm_ctx_pool_by_name(lm_ctx_t *ctx, char *name) {
|
||||
lm_pool_t *cur = ctx->pools;
|
||||
while (NULL != cur) {
|
||||
if (eq(cur->name, name))
|
||||
|
@ -17,7 +17,9 @@ bool __lm_ctx_resolve(lm_ctx_t *ctx, lm_ctx_resolve_list_t *list, lm_pkg_t *pkg)
|
||||
list->resolving = pkglist_add(list->resolving, pkg);
|
||||
|
||||
for(int i = 0; pkg->depends[i] != NULL; i++){
|
||||
lm_pkg_t *depend = lm_ctx_find(ctx, pkg->depends[i], NULL);
|
||||
// TODO: check if exists in the db before checking pools
|
||||
lm_pkg_t *depend = lm_ctx_pool_find(ctx, pkg->depends[i], NULL);
|
||||
|
||||
if(NULL == depend){
|
||||
lm_error_set(LM_ERR_DependNotFound, pkg->depends[i], pkg->name);
|
||||
return false;
|
||||
|
@ -21,10 +21,10 @@ char *queries[] = {
|
||||
"INSERT INTO packages VALUES (?, ?, ?, ?, ?)",
|
||||
|
||||
// QUERY_SELECT_PACKAGE_SINGLE
|
||||
"SELECT * FROM packages WHERE name = '?'",
|
||||
"SELECT * FROM packages WHERE name = ?",
|
||||
|
||||
// QUERY_DELETE_PACKAGE_SINGLE
|
||||
"DELETE FROM packages WHERE name = '?'",
|
||||
"DELETE FROM packages WHERE name = ?",
|
||||
|
||||
// QUERY_SELECT_PACKAGE_ALL
|
||||
"SELECT * FROM packages",
|
||||
@ -40,19 +40,19 @@ char *queries[] = {
|
||||
"INSERT INTO files VALUES (?, ?, ?, ?)",
|
||||
|
||||
// QUERY_DELETE_FILE_ALL
|
||||
"DELETE FROM files WHERE package = '?'",
|
||||
"DELETE FROM files WHERE package = ?",
|
||||
|
||||
// QUERY_SELECT_FILE_SINGLE
|
||||
"SELECT * FROM files WHERE path = ?",
|
||||
|
||||
// QUERY_SELECT_FILE_ALL
|
||||
"SELECT * FROM files WHERE package = '?'",
|
||||
"SELECT * FROM files WHERE package = ?",
|
||||
|
||||
// QUERY_UPDATE_FILE_1
|
||||
"UPDATE files SET keep = 1 WHERE path = '?'",
|
||||
"UPDATE files SET keep = 1 WHERE path = ?",
|
||||
|
||||
// QUERY_UPDATE_FILE_2
|
||||
"UPDATE files SET keep = 0 WHERE path = '?'",
|
||||
"UPDATE files SET keep = 0 WHERE path = ?",
|
||||
};
|
||||
|
||||
lm_database_t *lm_database_new(char *path){
|
||||
|
@ -32,9 +32,10 @@ bool lm_database_package_add(lm_database_t *db, lm_pkg_t *pkg){
|
||||
pdebug(__func__, "failed to convert depends to string for inserting %s: %s", pkg->name, lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
pdebug(__func__, "depend list for %s: %s", pkg->name, depends);
|
||||
sqlite3_bind_text(db->packages_st, PACKAGES_COLUMN_DEPENDS, depends, strlen(depends), SQLITE_STATIC);
|
||||
|
||||
if(sqlite3_step(db->packages_st) != SQLITE_DONE){
|
||||
if(!lm_database_step_all(db->packages_st)){
|
||||
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->packages_db));
|
||||
lm_error_set(LM_ERR_DbSqlInsertFail);
|
||||
goto end;
|
||||
|
@ -87,11 +87,12 @@ bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
|
||||
|
||||
if(i == 0){
|
||||
memcpy(buffer, pkg->depends[i], depsz);
|
||||
bufsz += depsz;
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer[bufsz++] = ',';
|
||||
memcpy(buffer+bufsz, pkg->depends, depsz);
|
||||
memcpy(buffer+bufsz, pkg->depends[i], depsz);
|
||||
bufsz += depsz;
|
||||
}
|
||||
|
||||
@ -111,9 +112,15 @@ bool lm_package_depend_fromstr(lm_pkg_t *pkg, char *buffer){
|
||||
return true;
|
||||
|
||||
char *save = NULL, *dep = NULL;
|
||||
while((dep = strtok_r(buffer, ",", &save)) != NULL)
|
||||
dep = strtok_r(buffer, ",", &save);
|
||||
|
||||
if(NULL == dep)
|
||||
return true;
|
||||
|
||||
do {
|
||||
if(!lm_package_depend_add(pkg, dep))
|
||||
return false;
|
||||
}while((dep = strtok_r(NULL, ",", &save)) != NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user