update: redesigning ctx functions and structure
This commit is contained in:
52
src/database/changes.c
Normal file
52
src/database/changes.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include "../../include/database.h"
|
||||
#include "../../include/error.h"
|
||||
#include "../../include/util.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file){
|
||||
if(NULL == db || NULL == pkg || NULL == file){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
char changes_file[strlen(db->dir)+strlen(pkg->name)+20];
|
||||
join_multiple(changes_file, db->dir, pkg->name, "changes");
|
||||
|
||||
if(!copy_file(changes_file, file))
|
||||
return false; // error set by function
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
|
||||
if(NULL == db || NULL == pkg){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
char changes_file[strlen(db->dir)+strlen(pkg->name)+20];
|
||||
join_multiple(changes_file, db->dir, pkg->name, "changes");
|
||||
|
||||
if(unlink(changes_file) < 0 && errno != ENOENT){
|
||||
lm_error_set(LM_ERR_DbChangesUnlinkFail);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg){
|
||||
char *changes_file = malloc(strlen(db->dir)+strlen(pkg->name)+20);
|
||||
join_multiple(changes_file, db->dir, pkg->name, "changes");
|
||||
|
||||
if(!exists(changes_file)){
|
||||
free(changes_file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return changes_file;
|
||||
}
|
Reference in New Issue
Block a user