libmp/src/package/package.c

61 lines
1.3 KiB
C

#include "../../include/package.h"
#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));
lm_package_init(pkg);
return pkg;
}
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;
}
bool lm_package_is_same(lm_pkg_t *one, lm_pkg_t *two){
return eq(one->version, two->version) &&
eq(one->name, two->name) &&
eq(one->desc, two->desc) &&
one->size == two->size;
}
void lm_package_free(lm_pkg_t *pkg){
lm_package_data_free(pkg);
bzero(pkg, sizeof(lm_pkg_t));
}