diff --git a/include/database.h b/include/database.h index 3a557d0..6e22d90 100644 --- a/include/database.h +++ b/include/database.h @@ -15,13 +15,15 @@ enum lm_query_index { QUERY_SELECT_ENTRY_SINGLE_2 = 3, QUERY_DELETE_ENTRY_SINGLE = 4, QUERY_SELECT_ENTRY_ALL = 5, - QUERY_CREATE_FILE_TABLE = 6, - QUERY_INSERT_FILE_SINGLE = 7, - QUERY_DELETE_FILE_ALL = 8, - QUERY_SELECT_FILE_SINGLE = 9, - QUERY_SELECT_FILE_ALL = 10, - QUERY_UPDATE_FILE_1 = 11, - QUERY_UPDATE_FILE_2 = 12, + + QUERY_CREATE_FILE_TABLE = 6, + QUERY_INSERT_FILE_SINGLE = 7, + QUERY_DELETE_FILE_ALL = 8, + QUERY_DELETE_FILE_SINGLE = 9, + QUERY_SELECT_FILE_ALL = 10, + QUERY_SELECT_FILE_SINGLE = 11, + QUERY_UPDATE_FILE_1 = 12, + QUERY_UPDATE_FILE_2 = 13, }; enum lm_columns { @@ -78,6 +80,7 @@ bool lm_database_files_next( bool lm_database_files_add( lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database bool lm_database_files_del(lm_database_t *db, lm_entry_t *entry); // dels all files of belonging to a entry +bool lm_database_files_del_single(lm_database_t *db, char *path); void lm_database_files_next_free(lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep); // frees resources used for lm_database_files_next diff --git a/src/ctx/install.c b/src/ctx/install.c index 1f3da4f..29b4322 100644 --- a/src/ctx/install.c +++ b/src/ctx/install.c @@ -141,6 +141,11 @@ bool __lm_ctx_extract_files(lm_ctx_t *ctx, lm_pkg_t *pkg, char *files, lm_ctx_in continue; } + if(exists(entry_path) && lm_database_files_iskeep(ctx->db, entry_path)){ + pdebug(__func__, "not extracting %s, file is set as KEEP", entry_path); + continue; + } + rc = archive_write_header(writer, entry); if (rc != ARCHIVE_OK) { lm_error_set(LM_ERR_ArcWHeaderFail); @@ -215,6 +220,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_insta lm_error_set(LM_ERR_PkgPathsEmpty); return false; } + + lm_ctx_temp_clear(ctx); if(!extract_archive(ctx->temp, pkg->archive)) return false; // error set by function @@ -290,6 +297,8 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, bool run_install, lm_ctx_insta pdebug(__func__, "(%lu) %s => %s", line_len, file, hash); + lm_database_files_del_single(ctx->db, file); + if(!lm_database_files_add(ctx->db, &pkg->data, file, hash)){ char *suberr = lm_strerror_dup(); pdebug(__func__, "failed to add file to the database for %s: %s", pkg->data.name, suberr); diff --git a/src/ctx/remove.c b/src/ctx/remove.c index f8d6b1d..a34ff7c 100644 --- a/src/ctx/remove.c +++ b/src/ctx/remove.c @@ -3,10 +3,10 @@ #include "../../include/util.h" #include "../../include/ctx.h" -#include #include #include #include +#include bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry){ if(NULL == ctx && NULL == entry){ diff --git a/src/ctx/sync.c b/src/ctx/sync.c index 18fddc4..1b92f9c 100644 --- a/src/ctx/sync.c +++ b/src/ctx/sync.c @@ -99,6 +99,7 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac goto next_list; } + lm_ctx_temp_clear(ctx); tempdir = lm_ctx_temp_dir(ctx, "list_extracted"); if(!do_update && !lm_pool_list_load(cur, tempdir)){ diff --git a/src/database/database.c b/src/database/database.c index 91be89d..97922c6 100644 --- a/src/database/database.c +++ b/src/database/database.c @@ -43,13 +43,16 @@ char *queries[] = { "INSERT INTO files VALUES (?, ?, ?, ?)", // QUERY_DELETE_FILE_ALL - "DELETE FROM files WHERE package = ?", + "DELETE FROM files WHERE package = ? AND keep = 1", - // QUERY_SELECT_FILE_SINGLE - "SELECT * FROM files WHERE path = ?", + // QUERY_DELETE_FILE_SINGLE + "DELETE FROM files WHERE path = ?", // QUERY_SELECT_FILE_ALL "SELECT * FROM files WHERE package = ?", + + // QUERY_SELECT_FILE_SINGLE + "SELECT * FROM files WHERE path = ?", // QUERY_UPDATE_FILE_1 "UPDATE files SET keep = 1 WHERE path = ?", diff --git a/src/database/files.c b/src/database/files.c index bbb09de..dffa480 100644 --- a/src/database/files.c +++ b/src/database/files.c @@ -207,6 +207,37 @@ end: return ret; } +bool lm_database_files_del_single(lm_database_t *db, char *path){ + if(NULL == db || NULL == path){ + lm_error_set(LM_ERR_ArgNULL); + return false; + } + + bool ret = false; + + if(sqlite3_prepare(db->files_db, queries[QUERY_DELETE_FILE_SINGLE], strlen(queries[QUERY_DELETE_FILE_SINGLE]), &db->files_st, NULL) != SQLITE_OK){ + pdebug(__func__, "failed to prepare statement for deleting %s: %s", path, sqlite3_errmsg(db->files_db)); + lm_error_set(LM_ERR_DbSqlPrepareFail); + goto end; + } + + sqlite3_bind_text(db->files_st, 1, path, strlen(path), SQLITE_STATIC); + + if(!lm_database_step_all(db->files_st)){ + pdebug(__func__, "failed to execute delete statement for deleting %s: %s", path, sqlite3_errmsg(db->files_db)); + lm_error_set(LM_ERR_DbSqlDeleteFail); + goto end; + } + + ret = true; +end: + if(NULL != db->files_st){ + sqlite3_finalize(db->files_st); + db->files_st = NULL; + } + return ret; +} + bool lm_database_files_next(lm_database_t *db, lm_entry_t *entry, char **path, char **hash, bool *keep){ if(NULL == db || NULL == entry || NULL == path || NULL == hash || NULL == keep){ lm_error_set(LM_ERR_ArgNULL);