fix: remove operation file check fixes

This commit is contained in:
ngn 2024-07-08 13:08:45 +03:00
parent 216ca5c9dd
commit d0dce209fa
5 changed files with 40 additions and 13 deletions

View File

@ -44,6 +44,8 @@ int main(int argc, char *argv[]) {
goto end;
}
printf("removing package: %s (%s)...\n", pkg.name, pkg.version);
if (!lm_ctx_remove(&ctx, &pkg, NULL, NULL)) {
printf("failed to remove package: %s (%d)\n", lm_strerror(), lm_error());
goto end;

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-08 12:47+0300\n"
"POT-Creation-Date: 2024-07-08 13:05+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"

View File

@ -15,6 +15,14 @@
#include <unistd.h>
bool __lm_ctx_run_install(char *root, char *install_path) {
struct stat st;
bzero(&st, sizeof(st));
stat(install_path, &st);
// no need to run empty install script :)
if(st.st_size <= 0)
return true;
char *args[] = {"/bin/bash", install_path, NULL}, *oldpwd = NULL;
bool ret = false;
int status = 0;

View File

@ -14,6 +14,11 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
return false;
}
if(NULL == ctx->root){
lm_error_set(LM_ERR_CtxRootNULL);
return false;
}
if(!lm_ctx_database_is_installed(ctx, pkg, true)){
lm_error_set(LM_ERR_PkgNotInstalled);
return false;
@ -22,8 +27,8 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
if(!lm_ctx_database_init(ctx))
return false;
char *path = NULL, *hash = NULL, *fpath = NULL;
size_t total = 0, current = 0;
char *path = NULL, *hash = NULL;
bool in_keep = false, ret = false;
total = lm_database_files_count(ctx->db, pkg);
@ -31,14 +36,26 @@ bool lm_ctx_remove(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_remove_callback_t callba
while(lm_database_files_next(ctx->db, pkg, &path, &hash, &in_keep)){
if(in_keep)
goto next;
if(exists(path) && unlink(path) < 0){
pdebug(__func__, "failed to delete file for removing %s: %s", pkg->name, errno);
lm_error_set(LM_ERR_PkgFileUnlinkFail, path, strerror(errno));
goto end;
fpath = join_alloc(ctx->root, path);
pdebug(__func__, "removing file %s (%s)", fpath, pkg->name);
if(!exists(fpath)){
pdebug(__func__, "found file in database, but its not on the file system: %s", fpath);
goto next;
}
if(unlink(fpath) < 0){
pdebug(__func__, "failed to delete file for removing %s: %s", pkg->name, strerror(errno));
lm_error_set(LM_ERR_PkgFileUnlinkFail, path, strerror(errno));
goto next;
}
next:
if(!callback(ctx, pkg, path, ++current, total, data))
free(fpath);
fpath = NULL;
if(NULL != callback && !callback(ctx, pkg, fpath, ++current, total, data))
goto end;
}

View File

@ -25,7 +25,7 @@ size_t lm_database_files_count(lm_database_t *db, lm_pkg_t *pkg){
return false;
}
sqlite3_bind_text(db->files_st, FILES_COLUMN_PACKAGE, pkg->name, strlen(pkg->name), SQLITE_STATIC);
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
while(sqlite3_step(db->files_st) == SQLITE_ROW)
count++;
@ -85,7 +85,7 @@ bool lm_database_files_matches(lm_database_t *db, char *path, char *hash){
goto end;
}
sqlite3_bind_text(db->files_st, FILES_COLUMN_PATH, path, strlen(path), SQLITE_STATIC);
sqlite3_bind_text(db->files_st, 1, path, strlen(path), SQLITE_STATIC);
if(sqlite3_step(db->files_st) != SQLITE_ROW){
pdebug(__func__, "failed to execute select statement for selecting %s: %s", path, sqlite3_errmsg(db->files_db));
@ -119,7 +119,7 @@ bool lm_database_files_iskeep(lm_database_t *db, char *path){
goto end;
}
sqlite3_bind_text(db->files_st, FILES_COLUMN_PATH, path, strlen(path), SQLITE_STATIC);
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 select statement for selecting %s: %s", path, sqlite3_errmsg(db->files_db));
@ -190,7 +190,7 @@ bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg){
goto end;
}
sqlite3_bind_text(db->files_st, FILES_COLUMN_PACKAGE, pkg->name, strlen(pkg->name), SQLITE_STATIC);
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
if(!lm_database_step_all(db->files_st)){
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->files_db));
@ -219,7 +219,7 @@ bool lm_database_files_next(lm_database_t *db, lm_pkg_t *pkg, char **path, char
lm_error_set(LM_ERR_DbSqlPrepareFail);
return false;
}
sqlite3_bind_text(db->files_st, FILES_COLUMN_PACKAGE, pkg->name, strlen(pkg->name), SQLITE_STATIC);
sqlite3_bind_text(db->files_st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
}
else if(NULL != db->files_st){