fix: keep files during updates
This commit is contained in:
parent
7c3d0dc1f8
commit
b27e31c66c
@ -15,13 +15,15 @@ enum lm_query_index {
|
|||||||
QUERY_SELECT_ENTRY_SINGLE_2 = 3,
|
QUERY_SELECT_ENTRY_SINGLE_2 = 3,
|
||||||
QUERY_DELETE_ENTRY_SINGLE = 4,
|
QUERY_DELETE_ENTRY_SINGLE = 4,
|
||||||
QUERY_SELECT_ENTRY_ALL = 5,
|
QUERY_SELECT_ENTRY_ALL = 5,
|
||||||
QUERY_CREATE_FILE_TABLE = 6,
|
|
||||||
QUERY_INSERT_FILE_SINGLE = 7,
|
QUERY_CREATE_FILE_TABLE = 6,
|
||||||
QUERY_DELETE_FILE_ALL = 8,
|
QUERY_INSERT_FILE_SINGLE = 7,
|
||||||
QUERY_SELECT_FILE_SINGLE = 9,
|
QUERY_DELETE_FILE_ALL = 8,
|
||||||
QUERY_SELECT_FILE_ALL = 10,
|
QUERY_DELETE_FILE_SINGLE = 9,
|
||||||
QUERY_UPDATE_FILE_1 = 11,
|
QUERY_SELECT_FILE_ALL = 10,
|
||||||
QUERY_UPDATE_FILE_2 = 12,
|
QUERY_SELECT_FILE_SINGLE = 11,
|
||||||
|
QUERY_UPDATE_FILE_1 = 12,
|
||||||
|
QUERY_UPDATE_FILE_2 = 13,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum lm_columns {
|
enum lm_columns {
|
||||||
@ -78,6 +80,7 @@ bool lm_database_files_next(
|
|||||||
bool lm_database_files_add(
|
bool lm_database_files_add(
|
||||||
lm_database_t *db, lm_entry_t *entry, char *path, char *hash); // adds a file to the files database
|
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(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,
|
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
|
bool *keep); // frees resources used for lm_database_files_next
|
||||||
|
|
||||||
|
@ -141,6 +141,11 @@ bool __lm_ctx_extract_files(lm_ctx_t *ctx, lm_pkg_t *pkg, char *files, lm_ctx_in
|
|||||||
continue;
|
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);
|
rc = archive_write_header(writer, entry);
|
||||||
if (rc != ARCHIVE_OK) {
|
if (rc != ARCHIVE_OK) {
|
||||||
lm_error_set(LM_ERR_ArcWHeaderFail);
|
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);
|
lm_error_set(LM_ERR_PkgPathsEmpty);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lm_ctx_temp_clear(ctx);
|
||||||
|
|
||||||
if(!extract_archive(ctx->temp, pkg->archive))
|
if(!extract_archive(ctx->temp, pkg->archive))
|
||||||
return false; // error set by function
|
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);
|
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)){
|
if(!lm_database_files_add(ctx->db, &pkg->data, file, hash)){
|
||||||
char *suberr = lm_strerror_dup();
|
char *suberr = lm_strerror_dup();
|
||||||
pdebug(__func__, "failed to add file to the database for %s: %s", pkg->data.name, suberr);
|
pdebug(__func__, "failed to add file to the database for %s: %s", pkg->data.name, suberr);
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#include "../../include/util.h"
|
#include "../../include/util.h"
|
||||||
#include "../../include/ctx.h"
|
#include "../../include/ctx.h"
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry){
|
bool lm_ctx_removeable(lm_ctx_t *ctx, lm_entry_t *entry){
|
||||||
if(NULL == ctx && NULL == entry){
|
if(NULL == ctx && NULL == entry){
|
||||||
|
@ -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;
|
goto next_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lm_ctx_temp_clear(ctx);
|
||||||
tempdir = lm_ctx_temp_dir(ctx, "list_extracted");
|
tempdir = lm_ctx_temp_dir(ctx, "list_extracted");
|
||||||
|
|
||||||
if(!do_update && !lm_pool_list_load(cur, tempdir)){
|
if(!do_update && !lm_pool_list_load(cur, tempdir)){
|
||||||
|
@ -43,13 +43,16 @@ char *queries[] = {
|
|||||||
"INSERT INTO files VALUES (?, ?, ?, ?)",
|
"INSERT INTO files VALUES (?, ?, ?, ?)",
|
||||||
|
|
||||||
// QUERY_DELETE_FILE_ALL
|
// QUERY_DELETE_FILE_ALL
|
||||||
"DELETE FROM files WHERE package = ?",
|
"DELETE FROM files WHERE package = ? AND keep = 1",
|
||||||
|
|
||||||
// QUERY_SELECT_FILE_SINGLE
|
// QUERY_DELETE_FILE_SINGLE
|
||||||
"SELECT * FROM files WHERE path = ?",
|
"DELETE FROM files WHERE path = ?",
|
||||||
|
|
||||||
// QUERY_SELECT_FILE_ALL
|
// QUERY_SELECT_FILE_ALL
|
||||||
"SELECT * FROM files WHERE package = ?",
|
"SELECT * FROM files WHERE package = ?",
|
||||||
|
|
||||||
|
// QUERY_SELECT_FILE_SINGLE
|
||||||
|
"SELECT * FROM files WHERE path = ?",
|
||||||
|
|
||||||
// QUERY_UPDATE_FILE_1
|
// QUERY_UPDATE_FILE_1
|
||||||
"UPDATE files SET keep = 1 WHERE path = ?",
|
"UPDATE files SET keep = 1 WHERE path = ?",
|
||||||
|
@ -207,6 +207,37 @@ end:
|
|||||||
return ret;
|
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){
|
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){
|
if(NULL == db || NULL == entry || NULL == path || NULL == hash || NULL == keep){
|
||||||
lm_error_set(LM_ERR_ArgNULL);
|
lm_error_set(LM_ERR_ArgNULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user