dataman: explicitly check file existence to init

- on NuttX if the SD card was just cleared (quick format) it's possible for the newly created uninitialized dataman file to still have the previous compatibility key, which causes the initialization to be skipped
This commit is contained in:
Daniel Agar
2023-09-08 10:16:24 -04:00
committed by GitHub
parent def4ce6ba8
commit 3476831246
+3 -1
View File
@@ -529,6 +529,8 @@ _file_clear(dm_item_t item)
static int
_file_initialize(unsigned max_offset)
{
const bool file_existed = (access(k_data_manager_device_path, F_OK) == 0);
/* Open or create the data manager file */
dm_operations_data.file.fd = open(k_data_manager_device_path, O_RDWR | O_CREAT | O_BINARY, PX4_O_MODE_666);
@@ -553,7 +555,7 @@ _file_initialize(unsigned max_offset)
dm_operations_data.silence = false;
if (compat_state.key != DM_COMPAT_KEY) {
if (!file_existed || (compat_state.key != DM_COMPAT_KEY)) {
/* Write current compat info */
compat_state.key = DM_COMPAT_KEY;