new: cleaning up functions, base implementation of install function

This commit is contained in:
ngn
2024-07-04 03:12:33 +03:00
parent 43cf7d26c8
commit 38b99eda79
25 changed files with 568 additions and 253 deletions

View File

@ -2,9 +2,12 @@
#include "../../include/error.h"
#include "../../include/types.h"
#include "../../include/mptp.h"
#include "../../include/util.h"
#include <errno.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
lm_pkg_t *lm_package_new(){
lm_pkg_t *pkg = malloc(sizeof(lm_pkg_t));
@ -16,6 +19,34 @@ void lm_package_init(lm_pkg_t *pkg){
bzero(pkg, sizeof(lm_pkg_t));
}
bool lm_package_downloaded(lm_pkg_t *pkg){
if(lm_package_path_is_empty(pkg)){
lm_error_set(LM_ERR_PkgPathsEmpty);
return false;
}
if(!exists(pkg->paths.archive) || !exists(pkg->paths.signature)){
lm_error_set(LM_ERR_PkgNotDownloaded);
return false;
}
return true;
}
bool lm_package_remove_download(lm_pkg_t *pkg){
if(unlink(pkg->paths.archive) < 0 && errno != ENOENT){
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
return false;
}
if(unlink(pkg->paths.signature) < 0 && errno != ENOENT){
lm_error_set(LM_ERR_PkgRemoveDownloadFail);
return false;
}
return true;
}
void lm_package_free(lm_pkg_t *pkg){
lm_package_data_free(pkg);
bzero(pkg, sizeof(lm_pkg_t));

View File

@ -11,10 +11,9 @@ bool lm_package_verify(lm_pkg_t *pkg){
return false;
}
if(lm_package_path_is_empty(pkg)){
lm_error_set(LM_ERR_PkgPathsEmpty);
// error set by function
if(!lm_package_downloaded(pkg))
return false;
}
gpgme_data_t sig = NULL, text = NULL;
gpgme_ctx_t ctx = NULL;