update: better package database

This commit is contained in:
ngn
2024-08-15 02:16:16 +03:00
parent e0f0dec222
commit 472cb9004e
11 changed files with 424 additions and 371 deletions

View File

@ -8,18 +8,31 @@
#include <string.h>
#include <unistd.h>
size_t __lm_database_changes_get(lm_database_t *db, lm_entry_t *entry, char *path){
size_t changes_size = strlen(entry->name)+15;
size_t full_size = changes_size + strlen(db->dir);
if(NULL != path){
char changes_file[changes_size];
snprintf(changes_file, changes_size, "%s_changes", entry->name);
join(path, db->dir, changes_file);
}
return full_size;
}
#define __lm_changes_size() __lm_database_changes_get(db, entry, NULL)
#define __lm_changes_path(p) __lm_database_changes_get(db, entry, p)
bool lm_database_changes_update(lm_database_t *db, lm_entry_t *entry, char *file){
if(NULL == db || NULL == entry || NULL == file){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char changes_file[strlen(entry->name)+20];
sprintf(changes_file, "%s_changes", entry->name);
char changes_path[strlen(db->dir)+sizeof(changes_file)];
join(changes_path, db->dir, changes_file);
char changes_path[__lm_changes_size()];
__lm_changes_path(changes_path);
if(!copy_file(changes_path, file))
return false;
@ -37,11 +50,8 @@ bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry){
return false;
}
char changes_file[strlen(entry->name)+20];
sprintf(changes_file, "%s_changes", entry->name);
char changes_path[strlen(db->dir)+sizeof(changes_file)];
join(changes_path, db->dir, changes_file);
char changes_path[__lm_changes_size()];
__lm_changes_path(changes_path);
if(unlink(changes_path) < 0 && errno != ENOENT){
lm_error_set(LM_ERR_DbChangesUnlinkFail);
@ -52,15 +62,16 @@ bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry){
}
char *lm_database_changes_get(lm_database_t *db, lm_entry_t *entry){
char changes_file[strlen(entry->name)+20];
sprintf(changes_file, "%s_changes", entry->name);
if(NULL == db || NULL == entry){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
char *changes_path = malloc(strlen(db->dir)+sizeof(changes_file));
join(changes_path, db->dir, changes_file);
char* changes_path = malloc(__lm_changes_size());
__lm_changes_path(changes_path);
if(!exists(changes_path, NULL)){
lm_error_set(LM_ERR_DbChangesNotExists);
free(changes_path);
return NULL;
}