settings: file: do not create file when loading

File backend can be read-only with the use of `settings_file_src()` API. It
makes no sense to create file when `settings_load()` is called and
registered file backend won't be used for saving files (because
`settings_file_dst()` was not used).

Do not create file during `settings_load()` if it does not exist yet. This
just requires to remove FS_O_CREATE flag in `fs_open()` invocation.

Open file with read-only access, which is now possible after removal of
`FS_O_CREATE` flag.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
Marcin Niestroj 2022-11-22 23:39:27 +01:00 committed by Carles Cufí
commit 976520c77e

View file

@ -137,8 +137,12 @@ static int settings_file_load_priv(struct settings_store *cs, line_load_cb cb,
fs_file_t_init(&file);
rc = fs_open(&file, cf->cf_name, FS_O_CREATE | FS_O_RDWR);
rc = fs_open(&file, cf->cf_name, FS_O_READ);
if (rc != 0) {
if (rc == -ENOENT) {
return -ENOENT;
}
return -EINVAL;
}