From b84bab36b94164b87257894b3de873f60bcee5e3 Mon Sep 17 00:00:00 2001 From: Miika Karanki Date: Mon, 30 Oct 2023 18:15:27 +0200 Subject: [PATCH] settings: file: do not unlink the settings file unnecessarily fs_rename can handle the file move atomically without unlinking the file first if the filesystem supports that. This change makes the settings file more power cut resilient so that the whole settings file is not lost with poorly timed power cut. Signed-off-by: Miika Karanki --- subsys/settings/src/settings_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subsys/settings/src/settings_file.c b/subsys/settings/src/settings_file.c index 5f8be73cf74..4f18a75c561 100644 --- a/subsys/settings/src/settings_file.c +++ b/subsys/settings/src/settings_file.c @@ -351,7 +351,7 @@ static int settings_file_save_and_compress(struct settings_file *cf, rc = fs_close(&wf); rc2 = fs_close(&rf); - if (rc == 0 && rc2 == 0 && fs_unlink(cf->cf_name) == 0) { + if (rc == 0 && rc2 == 0) { if (fs_rename(tmp_file, cf->cf_name)) { return -ENOENT; }