]> git.meshlink.io Git - meshlink/commitdiff
Sync invitation directory when calling meshlink_invite().
authorGuus Sliepen <guus@meshlink.io>
Tue, 5 Nov 2019 19:41:50 +0000 (20:41 +0100)
committerGuus Sliepen <guus@meshlink.io>
Tue, 5 Nov 2019 19:41:50 +0000 (20:41 +0100)
src/conf.c

index 79db093eeceefafa66fa193d665d4e8c3feb8861..eea9c3dd6245b8e8432af30f511d41c6f0f0ace6 100644 (file)
@@ -565,6 +565,12 @@ bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config,
 
                if(chacha_poly1305_encrypt_iv96(ctx, seqbuf, config->buf, config->len, buf, &len)) {
                        success = fwrite(seqbuf, sizeof(seqbuf), 1, f) == 1 && fwrite(buf, len, 1, f) == 1;
+
+                       if(!success) {
+                               logger(mesh, MESHLINK_ERROR, "Cannot write config file: %s", strerror(errno));
+                       }
+
+                       meshlink_errno = MESHLINK_ESTORAGE;
                } else {
                        logger(mesh, MESHLINK_ERROR, "Cannot encrypt config file\n");
                        meshlink_errno = MESHLINK_ESTORAGE;
@@ -588,6 +594,7 @@ bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config,
 
        if(fsync(fileno(f))) {
                logger(mesh, MESHLINK_ERROR, "Failed to sync file: %s\n", strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -701,6 +708,7 @@ bool config_write(meshlink_handle_t *mesh, const char *conf_subdir, const char *
 
        if(!f) {
                logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -712,11 +720,13 @@ bool config_write(meshlink_handle_t *mesh, const char *conf_subdir, const char *
 
        if(fclose(f)) {
                logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
        if(rename(tmp_path, path)) {
                logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -771,6 +781,7 @@ bool main_config_write(meshlink_handle_t *mesh, const char *conf_subdir, const c
 
        if(!f) {
                logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -782,12 +793,14 @@ bool main_config_write(meshlink_handle_t *mesh, const char *conf_subdir, const c
 
        if(rename(tmp_path, path)) {
                logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                fclose(f);
                return false;
        }
 
        if(fclose(f)) {
                logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -874,6 +887,7 @@ bool invitation_write(meshlink_handle_t *mesh, const char *conf_subdir, const ch
 
        if(!f) {
                logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }
 
@@ -885,6 +899,15 @@ bool invitation_write(meshlink_handle_t *mesh, const char *conf_subdir, const ch
 
        if(fclose(f)) {
                logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
+               return false;
+       }
+
+       snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "invitations", mesh->confbase, conf_subdir);
+
+       if(!sync_path(path)) {
+               logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno));
+               meshlink_errno = MESHLINK_ESTORAGE;
                return false;
        }