}
static bool meshlink_setup(meshlink_handle_t *mesh) {
+ if(!config_destroy(mesh->confbase, "new")) {
+ logger(mesh, MESHLINK_ERROR, "Could not delete configuration in %s/new: %s\n", mesh->confbase, strerror(errno));
+ meshlink_errno = MESHLINK_ESTORAGE;
+ return false;
+ }
+
+ if(!config_destroy(mesh->confbase, "old")) {
+ logger(mesh, MESHLINK_ERROR, "Could not delete configuration in %s/old: %s\n", mesh->confbase, strerror(errno));
+ meshlink_errno = MESHLINK_ESTORAGE;
+ return false;
+ }
+
if(!config_init(mesh, "current")) {
logger(mesh, MESHLINK_ERROR, "Could not set up configuration in %s/current: %s\n", mesh->confbase, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
fclose(lockfile);
- /* TODO: do we need to remove confbase? Potential race condition? */
if(!sync_path(confbase)) {
logger(NULL, MESHLINK_ERROR, "Cannot sync directory %s: %s\n", confbase, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
pthread_mutex_lock(&mesh->mutex);
node_t *n = (node_t *)node;
- memmove(n->recent + 1, n->recent, (MAX_RECENT - 1) * sizeof(*n->recent));
- memcpy(n->recent, addr, SALEN(*addr));
- if(!node_write_config(mesh, n)) {
- logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+ if(node_add_recent_address(mesh, n, (sockaddr_t *)addr)) {
+ if(!node_write_config(mesh, n)) {
+ logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+ }
}
pthread_mutex_unlock(&mesh->mutex);