new: better way of handling files db
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "../../include/util.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -13,10 +14,13 @@ bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file){
|
||||
return false;
|
||||
}
|
||||
|
||||
char changes_file[strlen(db->dir)+strlen(pkg->name)+20];
|
||||
join_multiple(changes_file, db->dir, pkg->name, "changes");
|
||||
char changes_file[strlen(pkg->name)+20];
|
||||
sprintf(changes_file, "%s_changes", pkg->name);
|
||||
|
||||
if(!copy_file(changes_file, file))
|
||||
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
||||
join(changes_path, db->dir, changes_file);
|
||||
|
||||
if(!copy_file(changes_path, file))
|
||||
return false; // error set by function
|
||||
|
||||
return true;
|
||||
@ -28,10 +32,13 @@ bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
|
||||
return false;
|
||||
}
|
||||
|
||||
char changes_file[strlen(db->dir)+strlen(pkg->name)+20];
|
||||
join_multiple(changes_file, db->dir, pkg->name, "changes");
|
||||
char changes_file[strlen(pkg->name)+20];
|
||||
sprintf(changes_file, "%s_changes", pkg->name);
|
||||
|
||||
if(unlink(changes_file) < 0 && errno != ENOENT){
|
||||
char changes_path[strlen(db->dir)+sizeof(changes_file)];
|
||||
join(changes_path, db->dir, changes_file);
|
||||
|
||||
if(unlink(changes_path) < 0 && errno != ENOENT){
|
||||
lm_error_set(LM_ERR_DbChangesUnlinkFail);
|
||||
return false;
|
||||
}
|
||||
@ -40,13 +47,16 @@ bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg){
|
||||
}
|
||||
|
||||
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");
|
||||
char changes_file[strlen(pkg->name)+20];
|
||||
sprintf(changes_file, "%s_changes", pkg->name);
|
||||
|
||||
if(!exists(changes_file)){
|
||||
free(changes_file);
|
||||
char *changes_path = malloc(strlen(db->dir)+sizeof(changes_file));
|
||||
join(changes_path, db->dir, changes_file);
|
||||
|
||||
if(!exists(changes_path)){
|
||||
free(changes_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return changes_file;
|
||||
return changes_path;
|
||||
}
|
||||
|
Reference in New Issue
Block a user