Sync ref test result with current implementation.
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 44b2e02..a5e242f 100644 (file)
--- a/file.c
+++ b/file.c
@@ -702,7 +702,9 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
        if ((asprintf(&filename, "%s/.%s.uci-XXXXXX", ctx->confdir, p->e.name) < 0) || !filename)
                UCI_THROW(ctx, UCI_ERR_MEM);
 
-       mktemp(filename);
+       if (!mktemp(filename))
+               *filename = 0;
+
        if (!*filename) {
                free(filename);
                UCI_THROW(ctx, UCI_ERR_IO);
@@ -712,7 +714,7 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
                UCI_THROW(ctx, UCI_ERR_IO);
 
        /* open the config file for writing now, so that it is locked */
-       f1 = uci_open_stream(ctx, p->path, SEEK_SET, false, false);
+       f1 = uci_open_stream(ctx, p->path, NULL, SEEK_SET, true, true);
 
        /* flush unsaved changes and reload from delta file */
        UCI_TRAP_SAVE(ctx, done);
@@ -745,7 +747,7 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag
                        goto done;
        }
 
-       f2 = uci_open_stream(ctx, filename, SEEK_SET, true, true);
+       f2 = uci_open_stream(ctx, filename, p->path, SEEK_SET, true, true);
        uci_export(ctx, f2, p, false);
 
        fflush(f2);
@@ -862,7 +864,7 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na
        }
 
        UCI_TRAP_SAVE(ctx, done);
-       file = uci_open_stream(ctx, filename, SEEK_SET, false, false);
+       file = uci_open_stream(ctx, filename, NULL, SEEK_SET, false, false);
        ctx->err = 0;
        UCI_INTERNAL(uci_import, ctx, file, name, &package, true);
        UCI_TRAP_RESTORE(ctx);