new: implement database keeps and files functions

This commit is contained in:
ngn 2024-07-03 03:40:52 +03:00
parent 17a073838d
commit 43cf7d26c8
14 changed files with 461 additions and 32 deletions

View File

@ -2,6 +2,8 @@
#include "package.h"
#include <sqlite3.h>
#define HASH_LEN 32
typedef enum lm_query_index {
QUERY_CREATE_TABLE = 0,
QUERY_INSERT_PACKAGE = 1,
@ -12,8 +14,8 @@ typedef enum lm_query_index {
extern char *queries[];
typedef struct lm_database {
char *dir;
lm_pkg_t *pkg;
char *path;
sqlite3 *sql;
} lm_database_t;
@ -27,12 +29,13 @@ bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name);
bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func);
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func, void *data);
bool lm_database_files_matches(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash);
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func);
bool lm_database_keeps_contains(lm_database_t *db, lm_pkg_t *pkg, char *path);
bool lm_database_keeps_add(lm_database_t *db, lm_pkg_t *pkg, char *path);
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func, void *data);
bool lm_database_keeps_load(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_keeps_save(lm_database_t *db, lm_pkg_t *pkg);
bool lm_database_keeps_del(lm_database_t *db, lm_pkg_t *pkg);

View File

@ -81,6 +81,16 @@ typedef enum lm_error {
LM_ERR_PoolUrlEmpty = 76,
LM_ERR_PoolBadDir = 77,
LM_ERR_PoolBadPaths = 78,
LM_ERR_DbFilesNotFound = 79,
LM_ERR_DbFilesOpenFail = 80,
LM_ERR_DbFilesDirFail = 81,
LM_ERR_DbFilesUnlinkFail = 82,
LM_ERR_DbFilesWriteFail = 83,
LM_ERR_DbKeepsNotFound = 84,
LM_ERR_DbKeepsOpenFail = 85,
LM_ERR_DbKeepsDirFail = 86,
LM_ERR_DbKeepsUnlinkFail = 87,
LM_ERR_DbSqlNotFound = 88,
} lm_error_t;
typedef struct lm_error_desc {

View File

@ -6,6 +6,7 @@
#define PKG_DATA_DESC "desc"
#define PKG_DATA_VERSION "version"
#define PKG_DATA_DEPENDS "depends"
#define PKG_DATA_KEEPS "keeps"
lm_pkg_t *lm_package_new();
void lm_package_free(lm_pkg_t *pkg);
@ -25,6 +26,7 @@ void lm_package_depend_free(lm_pkg_t *pkg);
size_t lm_package_keep_count(lm_pkg_t *pkg);
bool lm_package_keep_add(lm_pkg_t *pkg, char *path);
bool lm_package_keep_contains(lm_pkg_t *pkg, char *path);
void lm_package_keep_free(lm_pkg_t *pkg);
bool lm_package_path_set_signature(lm_pkg_t *pkg, char *signature_path);
bool lm_package_path_set_archive(lm_pkg_t *pkg, char *archive_path);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-02 03:53+0300\n"
"POT-Creation-Date: 2024-07-03 03:40+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"
@ -306,41 +306,81 @@ msgid "failed to insert to the table in SQLite database"
msgstr ""
#: src/error.c:83
msgid "failed to init GPG for package verification"
msgid "failed to find entry in SQLite database"
msgstr ""
#: src/error.c:84
msgid "failed to import signature to GPG for package verification"
msgid "failed to init GPG for package verification"
msgstr ""
#: src/error.c:85
msgid "failed to import archive to GPG for package verification"
msgid "failed to import signature to GPG for package verification"
msgstr ""
#: src/error.c:86
msgid "package signature verification failed with zero matches"
msgid "failed to import archive to GPG for package verification"
msgstr ""
#: src/error.c:87
msgid "package signature verification failed with zero results"
msgid "package signature verification failed with zero matches"
msgstr ""
#: src/error.c:88
msgid "pool file and directory paths are empty"
msgid "package signature verification failed with zero results"
msgstr ""
#: src/error.c:89
msgid "pool is not avaliable for connection"
msgid "pool file and directory paths are empty"
msgstr ""
#: src/error.c:90
msgid "pool URL is empty or invalid"
msgid "pool is not avaliable for connection"
msgstr ""
#: src/error.c:91
msgid "pool directory path is not accessible"
msgid "pool URL is empty or invalid"
msgstr ""
#: src/error.c:92
msgid "pool directory path is not accessible"
msgstr ""
#: src/error.c:93
msgid "pool directory sub-paths are not accessible"
msgstr ""
#: src/error.c:94
msgid "package file list not found in the database"
msgstr ""
#: src/error.c:95
msgid "failed to open package file list in the database"
msgstr ""
#: src/error.c:96
msgid "failed to access package file list database directory"
msgstr ""
#: src/error.c:97
msgid "failed to remove package file list from the database"
msgstr ""
#: src/error.c:98
msgid "failed to write to the file list in the database"
msgstr ""
#: src/error.c:99
msgid "package keep list not found in the database"
msgstr ""
#: src/error.c:100
msgid "failed to open package keep list in the database"
msgstr ""
#: src/error.c:101
msgid "failed to access package keep list database directory"
msgstr ""
#: src/error.c:102
msgid "failed to remove package keep list from the database"
msgstr ""

View File

@ -6,6 +6,6 @@
lm_database_t *lm_ctx_database_new(lm_ctx_t *ctx){
char dbpath[strlen(ctx->data)+10];
join(dbpath, ctx->data, "packages.db");
join(dbpath, ctx->data, "db");
return lm_database_new(dbpath);
}

View File

@ -46,12 +46,11 @@ bool lm_ctx_package_verify(lm_ctx_t *ctx, char *name, char *version) {
bool lm_ctx_package_is_installed(lm_ctx_t *ctx, char *name, char *version) {
lm_database_t *db = lm_ctx_database_new(ctx);
lm_pkg_t pkg;
if(NULL == db)
return false;
bool ret = lm_database_find(db, NULL, name, version);
bool ret = lm_database_find(db, NULL, name);
lm_database_free(db);
return ret;

View File

@ -25,12 +25,15 @@ lm_database_t *lm_database_new(char *path){
char *err = NULL;
bzero(db, sizeof(lm_database_t));
if(exists(path) && !can_read(path)){
if(exists(path) && (is_file(path) || !can_read(path) || !can_write(path))){
lm_error_set(LM_ERR_DbCantAccess);
return NULL;
}
char dbfile[strlen(path)+20];
join(dbfile, path, "packages.db");
if(sqlite3_open(path, &db->sql)){
if(sqlite3_open(dbfile, &db->sql)){
pdebug(__func__, "(%s) failed to open databse: %s", path, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlOpenFail);
return NULL;
@ -42,13 +45,13 @@ lm_database_t *lm_database_new(char *path){
sqlite3_free(err);
}
db->path = strdup(path);
db->dir = strdup(path);
return db;
}
void lm_database_free(lm_database_t *db){
sqlite3_close(db->sql);
free(db->path);
free(db->dir);
lm_pkg_t *cur = db->pkg, *prev = NULL;
while(NULL != cur){

177
src/database/files.c Normal file
View File

@ -0,0 +1,177 @@
#include "../../include/database.h"
#include "../../include/package.h"
#include "../../include/error.h"
#include "../../include/util.h"
#include <stdio.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_files_eachfunc_t func, void *data){
if(NULL == db || NULL == pkg || NULL == func){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char files_list[strlen(db->dir)+strlen(pkg->name)+20];
join_multiple(files_list, db->dir, pkg->name, "files");
if(!exists(files_list)){
lm_error_set(LM_ERR_DbFilesNotFound);
return false;
}
FILE *files = fopen(files_list, "r");
char *line = NULL, hash[HASH_LEN+1];
size_t line_len = 0;
bool ret = false;
if(NULL == files){
lm_error_set(LM_ERR_DbFilesOpenFail);
goto end;
}
while(getline(&line, 0, files) > 0){
line_len = strlen(line);
char path[line_len+1];
if(HASH_LEN >= line_len)
continue;
memcpy(path, line+HASH_LEN+1, line_len-HASH_LEN);
memcpy(hash, line, HASH_LEN+1);
hash[HASH_LEN] = 0;
if(!func(pkg, path, hash, data))
goto end;
free(line);
line = NULL;
}
ret = true;
end:
free(line);
if(NULL != files)
fclose(files);
return ret;
}
bool lm_database_files_add(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash){
if(NULL == db || NULL == pkg || NULL == path || NULL == hash){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char pkg_dir[strlen(db->dir)+strlen(pkg->name)+5];
char files_list[sizeof(pkg_dir)+15];
bool ret = false;
join(pkg_dir, db->dir, pkg->name);
join(files_list, pkg_dir, "files");
if(!mkdir_ifnot(pkg_dir)){
lm_error_set(LM_ERR_DbFilesDirFail);
return false;
}
FILE *files = fopen(files_list, "a");
if(NULL == files){
lm_error_set(LM_ERR_DbFilesOpenFail);
goto end;
}
if(fprintf(files, "%s:%s\n", hash, path) < 0){
pdebug(__func__, "failed to append file to files list: %s", files_list);
lm_error_set(LM_ERR_DbFilesWriteFail);
goto end;
}
ret = true;
end:
if(NULL != files)
fclose(files);
return ret;
}
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash){
if(NULL == db || NULL == pkg || NULL == path || NULL == hash){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
// zero out the hash
bzero(hash, HASH_LEN+1);
char files_list[strlen(db->dir)+strlen(pkg->name)+10];
join_multiple(files_list, db->dir, pkg->name, "files");
if(!exists(files_list)){
lm_error_set(LM_ERR_DbFilesNotFound);
return false;
}
FILE *files = fopen(files_list, "r");
char *line = NULL;
size_t line_len = 0;
bool ret = false;
if(NULL == files){
lm_error_set(LM_ERR_DbFilesOpenFail);
goto end;
}
while(getline(&line, 0, files) > 0){
line_len = strlen(line);
char lpath[line_len+1];
if(HASH_LEN >= line_len)
continue;
memcpy(lpath, line+HASH_LEN+1, line_len-HASH_LEN);
if(eq(lpath, path)){
memcpy(hash, line, HASH_LEN+1);
hash[HASH_LEN] = 0;
ret = true;
goto end;
}
free(line);
line = NULL;
}
end:
free(line);
if(NULL != files)
fclose(files);
return ret;
}
bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg){
if(NULL == db || NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char files_list[strlen(db->dir)+strlen(pkg->name)+10];
join_multiple(files_list, db->dir, pkg->name, "files");
if(unlink(files_list) < 0 && errno != ENOENT){
pdebug(__func__, "failed to delete file list for %s: %s", pkg->name, files_list);
lm_error_set(LM_ERR_DbFilesUnlinkFail);
return false;
}
return true;
}

153
src/database/keeps.c Normal file
View File

@ -0,0 +1,153 @@
#include "../../include/database.h"
#include "../../include/package.h"
#include "../../include/error.h"
#include "../../include/util.h"
#include <stdio.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
bool lm_database_keeps_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_keeps_eachfunc_t func, void *data){
if(NULL == db || NULL == pkg || NULL == func){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char keeps_list[strlen(db->dir)+strlen(pkg->name)+20];
join_multiple(keeps_list, db->dir, pkg->name, "keeps");
if(!exists(keeps_list)){
lm_error_set(LM_ERR_DbKeepsNotFound);
return false;
}
FILE *keeps = fopen(keeps_list, "r");
char *line = NULL;
bool ret = false;
if(NULL == keeps){
lm_error_set(LM_ERR_DbKeepsOpenFail);
goto end;
}
while(getline(&line, 0, keeps) > 0){
if(line[0] == 0)
continue;
if(!func(pkg, line, data))
goto end;
free(line);
line = NULL;
}
ret = true;
end:
free(line);
if(NULL != keeps)
fclose(keeps);
return ret;
}
bool lm_database_keeps_load(lm_database_t *db, lm_pkg_t *pkg){
if(NULL == db || NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char keeps_list[strlen(db->dir)+strlen(pkg->name)+20];
join_multiple(keeps_list, db->dir, pkg->name, "keeps");
if(!exists(keeps_list)){
lm_error_set(LM_ERR_DbKeepsNotFound);
return false;
}
FILE *keeps = fopen(keeps_list, "r");
char *line = NULL;
bool ret = false;
if(NULL == keeps){
lm_error_set(LM_ERR_DbKeepsOpenFail);
goto end;
}
while(getline(&line, 0, keeps) > 0){
if(line[0] == 0)
continue;
if(!lm_package_keep_add(pkg, line))
goto end;
free(line);
line = NULL;
}
ret = true;
end:
free(line);
if(NULL != keeps)
fclose(keeps);
return ret;
}
bool lm_database_keeps_save(lm_database_t *db, lm_pkg_t *pkg){
if(NULL == db || NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char pkg_dir[strlen(db->dir)+strlen(pkg->name)+5];
char keeps_list[sizeof(pkg_dir)+15];
bool ret = false;
join(pkg_dir, db->dir, pkg->name);
join(keeps_list, pkg_dir, "keeps");
if(!mkdir_ifnot(pkg_dir)){
lm_error_set(LM_ERR_DbKeepsDirFail);
return false;
}
FILE *keeps = fopen(keeps_list, "a");
if(NULL == keeps){
lm_error_set(LM_ERR_DbKeepsOpenFail);
goto end;
}
for(int i = 0; NULL != pkg->keeps[i]; i++)
fprintf(keeps, "%s\n", pkg->keeps[i]);
ret = true;
end:
if(NULL != keeps)
fclose(keeps);
return ret;
}
bool lm_database_keeps_del(lm_database_t *db, lm_pkg_t *pkg){
if(NULL == db || NULL == pkg){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char keeps_list[strlen(db->dir)+strlen(pkg->name)+20];
join_multiple(keeps_list, db->dir, pkg->name, "keeps");
if(unlink(keeps_list) < 0 && errno != ENOENT){
pdebug(__func__, "failed to delete keep list for %s: %s", pkg->name, keeps_list);
lm_error_set(LM_ERR_DbKeepsUnlinkFail);
return false;
}
return true;
}

View File

@ -19,7 +19,7 @@ bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg){
bool ret = false;
if(sqlite3_prepare(db->sql, queries[QUERY_INSERT_PACKAGE], strlen(queries[QUERY_INSERT_PACKAGE]), &st, NULL) != SQLITE_OK){
pdebug(__func__, "(%s) failed to prepare statement: %s", db->path, sqlite3_errmsg(db->sql));
pdebug(__func__, "failed to prepare statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlPrepareFail);
goto end;
}
@ -30,13 +30,13 @@ bool lm_database_add(lm_database_t *db, lm_pkg_t *pkg){
sqlite3_bind_int64(st, 4, pkg->size);
if(!lm_package_depend_tostr(pkg, depends)){
pdebug(__func__, "(%s) failed to convert depends to string: %s", db->path, lm_strerror());
pdebug(__func__, "failed to convert depends to string for inserting %s: %s", pkg->name, lm_strerror());
goto end;
}
sqlite3_bind_text(st, 5, depends, strlen(depends), SQLITE_STATIC);
if(sqlite3_step(st) != SQLITE_DONE){
pdebug(__func__, "(%s) failed to execute insert statement: %s", db->path, sqlite3_errmsg(db->sql));
pdebug(__func__, "failed to execute insert statement for inserting %s: %s", pkg->name, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlInsertFail);
goto end;
}
@ -58,7 +58,7 @@ bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name){
bool ret = false;
if(sqlite3_prepare(db->sql, queries[QUERY_SELECT_PACKAGE], strlen(queries[QUERY_SELECT_PACKAGE]), &st, NULL) != SQLITE_OK){
pdebug(__func__, "(%s) failed to prepare statement: %s", db->path, sqlite3_errmsg(db->sql));
pdebug(__func__, "failed to prepare statement for finding %s: %s", name, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlPrepareFail);
goto end;
}
@ -66,7 +66,7 @@ bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name){
sqlite3_bind_text(st, 1, name, strlen(name), SQLITE_STATIC);
if(sqlite3_step(st) != SQLITE_ROW){
pdebug(__func__, "(%s) got no rows for %s", db->path, name);
pdebug(__func__, "got no rows for %s", name);
lm_error_set(LM_ERR_DbSqlNotFound);
goto end;
}
@ -87,7 +87,7 @@ bool lm_database_find(lm_database_t *db, lm_pkg_t *pkg, char *name){
char *depends = (char*)sqlite3_column_text(st, 3);
if(!lm_package_depend_fromstr(pkg, depends)){
pdebug(__func__, "(%s) failed to load depends for %s (%s): %s", db->path, name, lm_strerror());
pdebug(__func__, "failed to load depends for finding %s: %s", pkg->name, lm_strerror());
// error is set by the function
goto end;
}
@ -109,7 +109,7 @@ bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg){
bool ret = false;
if(sqlite3_prepare(db->sql, queries[QUERY_DELETE_PACKAGE], strlen(queries[QUERY_DELETE_PACKAGE]), &st, NULL) != SQLITE_OK){
pdebug(__func__, "(%s) failed to prepare statement: %s", db->path, sqlite3_errmsg(db->sql));
pdebug(__func__, "failed to prepare statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlPrepareFail);
goto end;
}
@ -117,7 +117,7 @@ bool lm_database_del(lm_database_t *db, lm_pkg_t *pkg){
sqlite3_bind_text(st, 1, pkg->name, strlen(pkg->name), SQLITE_STATIC);
if(sqlite3_step(st) != SQLITE_DONE){
pdebug(__func__, "(%s) failed to execute delete statement: %s", db->path, sqlite3_errmsg(db->sql));
pdebug(__func__, "failed to execute delete statement for deleting %s: %s", pkg->name, sqlite3_errmsg(db->sql));
lm_error_set(LM_ERR_DbSqlInsertFail);
goto end;
}

View File

@ -80,6 +80,7 @@ char *lm_strerror() {
{.code = LM_ERR_DbSqlCreateFail, .desc = _("failed to create table in SQLite database") },
{.code = LM_ERR_DbSqlPrepareFail, .desc = _("failed to prepare statement for SQLite database") },
{.code = LM_ERR_DbSqlInsertFail, .desc = _("failed to insert to the table in SQLite database") },
{.code = LM_ERR_DbSqlNotFound, .desc = _("failed to find entry in SQLite database") },
{.code = LM_ERR_PkgGPGFail, .desc = _("failed to init GPG for package verification") },
{.code = LM_ERR_PkgGPGSigFail, .desc = _("failed to import signature to GPG for package verification")},
{.code = LM_ERR_PkgGPGArchiveFail, .desc = _("failed to import archive to GPG for package verification") },
@ -90,6 +91,15 @@ char *lm_strerror() {
{.code = LM_ERR_PoolUrlEmpty, .desc = _("pool URL is empty or invalid") },
{.code = LM_ERR_PoolBadDir, .desc = _("pool directory path is not accessible") },
{.code = LM_ERR_PoolBadPaths, .desc = _("pool directory sub-paths are not accessible") },
{.code = LM_ERR_DbFilesNotFound, .desc = _("package file list not found in the database") },
{.code = LM_ERR_DbFilesOpenFail, .desc = _("failed to open package file list in the database") },
{.code = LM_ERR_DbFilesDirFail, .desc = _("failed to access package file list database directory") },
{.code = LM_ERR_DbFilesUnlinkFail, .desc = _("failed to remove package file list from the database") },
{.code = LM_ERR_DbFilesWriteFail, .desc = _("failed to write to the file list in the database") },
{.code = LM_ERR_DbKeepsNotFound, .desc = _("package keep list not found in the database") },
{.code = LM_ERR_DbKeepsOpenFail, .desc = _("failed to open package keep list in the database") },
{.code = LM_ERR_DbKeepsDirFail, .desc = _("failed to access package keep list database directory") },
{.code = LM_ERR_DbKeepsUnlinkFail, .desc = _("failed to remove package keep list from the database") },
};
for (int i = 0; i < sizeof(errors) / sizeof(lm_error_desc_t); i++) {

View File

@ -37,6 +37,11 @@ int lm_package_data_handler(void *data, const char *_section, const char *_key,
return 0;
}
else if(eq(key, PKG_DATA_KEEPS)){
if(!lm_package_keep_add(pkg, value))
return 0;
}
return 1;
}
@ -55,5 +60,7 @@ void lm_package_data_free(lm_pkg_t *pkg){
free(pkg->desc);
free(pkg->name);
free(pkg->version);
lm_package_depend_free(pkg);
lm_package_keep_free(pkg);
}

View File

@ -47,6 +47,9 @@ void lm_package_depend_free(lm_pkg_t *pkg){
if(NULL == pkg)
return;
if(NULL == pkg->depends)
return;
for(int i = 0; pkg->depends[i] != NULL; i++)
free(pkg->depends[i]);
free(pkg->depends);
@ -77,14 +80,22 @@ bool lm_package_depend_tostr(lm_pkg_t *pkg, char *buffer){
return true;
}
size_t bufsz = 0, depsz = 0;
for(int i = 0; NULL != pkg->depends[i]; i++){
depsz = strlen(pkg->depends[i]);
if(i == 0){
sprintf(buffer, "%s", pkg->depends[i]);
memcpy(buffer, pkg->depends[i], depsz);
continue;
}
sprintf(buffer, "%s,%s", buffer, pkg->depends[i]);
buffer[bufsz++] = ',';
memcpy(buffer+bufsz, pkg->depends, depsz);
bufsz += depsz;
}
buffer[bufsz] = 0;
return true;
}

View File

@ -53,3 +53,17 @@ bool lm_package_keep_contains(lm_pkg_t *pkg, char *path){
return false;
}
void lm_package_keep_free(lm_pkg_t *pkg){
if(NULL == pkg)
return;
if(NULL == pkg->keeps)
return;
for(int i = 0; pkg->keeps[i] != NULL; i++)
free(pkg->keeps[i]);
free(pkg->keeps);
pkg->keeps = NULL;
}