From bea8d13227ec01ba325f0bab512b0c16b1fea976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 29 Aug 2022 08:20:51 +0200 Subject: [PATCH] xC: don't autosave when nothing changed --- xC.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/xC.c b/xC.c index 84c5532..50ddbcb 100644 --- a/xC.c +++ b/xC.c @@ -11361,7 +11361,7 @@ handle_command_set_modify return result; } -static void +static bool handle_command_set_assign_item (struct app_context *ctx, char *key, struct config_item *new_, bool add, bool remove) { @@ -11384,14 +11384,14 @@ handle_command_set_assign_item (struct app_context *ctx, log_global_error (ctx, "Failed to set option \"#s\": #s", key, e->message); error_free (e); + return false; } - else - { - struct strv tmp = strv_make (); - dump_matching_options (ctx->config.root, key, &tmp); - log_global_status (ctx, "Option changed: #s", tmp.vector[0]); - strv_free (&tmp); - } + + struct strv tmp = strv_make (); + dump_matching_options (ctx->config.root, key, &tmp); + log_global_status (ctx, "Option changed: #s", tmp.vector[0]); + strv_free (&tmp); + return true; } static bool @@ -11427,15 +11427,18 @@ handle_command_set_assign config_item_destroy (new_); return true; } + + bool changed = false; for (size_t i = 0; i < all->len; i++) { char *key = cstr_cut_until (all->vector[i], " "); - handle_command_set_assign_item (ctx, key, new_, add, remove); + if (handle_command_set_assign_item (ctx, key, new_, add, remove)) + changed = true; free (key); } config_item_destroy (new_); - if (get_config_boolean (ctx->config.root, "general.autosave")) + if (changed && get_config_boolean (ctx->config.root, "general.autosave")) save_configuration (ctx); return true; }