fix: recover a collection cut off between remove and rename
store_save removes the old file before renaming the finished .tmp, so a restart between the two started that collection empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f47237696e
commit
4372ba4105
1 file changed
+9
@@ -47,6 +47,15 @@ static cJSON *load_file(const char *name)
|
|||||||
char path[48];
|
char path[48];
|
||||||
snprintf(path, sizeof(path), "/db/%s.json", name);
|
snprintf(path, sizeof(path), "/db/%s.json", name);
|
||||||
FILE *f = fopen(path, "rb");
|
FILE *f = fopen(path, "rb");
|
||||||
|
if (!f) {
|
||||||
|
// store_save removes the old file before renaming the finished .tmp, so a restart between the two leaves only .tmp
|
||||||
|
char tmp[48];
|
||||||
|
snprintf(tmp, sizeof(tmp), "/db/%s.tmp", name);
|
||||||
|
if (rename(tmp, path) == 0) {
|
||||||
|
ESP_LOGW(TAG, "%s: recovered from %s", path, tmp);
|
||||||
|
f = fopen(path, "rb");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!f) {
|
if (!f) {
|
||||||
return cJSON_CreateObject();
|
return cJSON_CreateObject();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user