}
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;
// Make sure we can start and stop the mesh again.
assert(meshlink_start(mesh));
+ assert(meshlink_start(mesh));
+ meshlink_stop(mesh);
meshlink_stop(mesh);
// Close the mesh and open it again, now with a different name parameter.
meshlink_stop(mesh);
meshlink_close(mesh);
+ // Check that messing with the config directory will create a new instance.
+
+ assert(unlink("basic_conf/current/meshlink.conf") == 0);
+ mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
+ assert(mesh);
+ assert(!meshlink_get_node(mesh, "foo"));
+ self = meshlink_get_self(mesh);
+ assert(self);
+ assert(!strcmp(self->name, "bar"));
+ assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
+ meshlink_close(mesh);
+
+ assert(rename("basic_conf/current", "basic_conf/new") == 0);
+ mesh = meshlink_open("basic_conf", "baz", "basic", DEV_CLASS_BACKBONE);
+ assert(mesh);
+ assert(!meshlink_get_node(mesh, "bar"));
+ self = meshlink_get_self(mesh);
+ assert(self);
+ assert(!strcmp(self->name, "baz"));
+ assert(access("basic_conf/new", X_OK) == -1 && errno == ENOENT);
+ meshlink_close(mesh);
+
// Destroy the mesh.
assert(meshlink_destroy("basic_conf"));
}
closedir(dir);
+
+ // Check that we can destroy it again.
+
+ assert(meshlink_destroy("basic_conf"));
}