diff mbox series

[uci] delta: simplify uci_load_delta() by using a helper

Message ID 20220816115744.20902-1-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series [uci] delta: simplify uci_load_delta() by using a helper | expand

Commit Message

Rafał Miłecki Aug. 16, 2022, 11:57 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

In the commit 3c7f3556b0039 ("Fix delta path handling.")
uci_load_delta() was modified by open coding uci_load_delta_file(). It
seems that reason behind it was to avoid uci_parse_delta(). The same can
be achieved by passing NULL as "struct uci_package *p" argument.

Cc: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 delta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/delta.c b/delta.c
index d8bd3a6..85ec970 100644
--- a/delta.c
+++ b/delta.c
@@ -293,7 +293,7 @@  error:
 }
 
 /* returns the number of changes that were successfully parsed */
-static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE **f, bool flush)
+static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE *volatile *f, bool flush)
 {
 	FILE *volatile stream = NULL;
 	volatile int changes = 0;
@@ -334,9 +334,7 @@  __private int uci_load_delta(struct uci_context *ctx, struct uci_package *p, boo
 
 	if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
 		UCI_THROW(ctx, UCI_ERR_MEM);
-	UCI_TRAP_SAVE(ctx, done);
-	f = uci_open_stream(ctx, filename, NULL, SEEK_SET, flush, false);
-	UCI_TRAP_RESTORE(ctx);
+	uci_load_delta_file(ctx, NULL, filename, &f, flush);
 
 	if (flush && f && (changes > 0)) {
 		if (ftruncate(fileno(f), 0) < 0) {
@@ -346,7 +344,6 @@  __private int uci_load_delta(struct uci_context *ctx, struct uci_package *p, boo
 		}
 	}
 
-done:
 	free(filename);
 	uci_close_stream(f);
 	ctx->err = 0;