#include "../../include/database.h" #include "../../include/error.h" #include "../../include/util.h" #include #include #include #include #include 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); if(!copy_file(changes_path, file)) return false; if(chmod(changes_path, 0444) < 0){ lm_error_set(LM_ERR_DbChangesChmodFail); return false; } return true; } bool lm_database_changes_del(lm_database_t *db, lm_entry_t *entry){ if(NULL == db || NULL == entry){ 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); if(unlink(changes_path) < 0 && errno != ENOENT){ lm_error_set(LM_ERR_DbChangesUnlinkFail); return false; } return true; } 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); char *changes_path = malloc(strlen(db->dir)+sizeof(changes_file)); join(changes_path, db->dir, changes_file); if(!exists(changes_path)){ lm_error_set(LM_ERR_DbChangesNotExists); free(changes_path); return NULL; } return changes_path; }