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 <miika.karanki@vaisala.com>
This commit is contained in:
Miika Karanki 2023-10-30 18:15:27 +02:00 committed by Henrik Brix Andersen
parent 3a1e179c4d
commit b84bab36b9
1 changed files with 1 additions and 1 deletions

View File

@ -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;
}