Skip to content

Commit 90dd66f

Browse files
committedNov 15, 2020
https://github.com/lorol/LITTLEFS/issues/10
Following: Sync file upon opening to free storage when overwriting a file joltwallet/esp_littlefs#22 Fixes out-of-storage issues when overwriting a file by syncing-on-open. Not that this effectively immediately deletes the file being overwritten. Based on: esp8266/Arduino#7434
1 parent f1f5e3a commit 90dd66f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎src/esp_littlefs.c

+16
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,22 @@ static int vfs_littlefs_open(void* ctx, const char * path, int flags, int mode)
927927
return LFS_ERR_INVAL;
928928
}
929929

930+
/* Sync after opening. If we are overwriting a file, this will free that
931+
* file's blocks in storage, prevent OOS errors.
932+
* See TEST_CASE:
933+
* "Rewriting file frees space immediately (#7426)"
934+
*/
935+
res = lfs_file_sync(efs->fs, &file->file);
936+
if(res < 0){
937+
errno = -res;
938+
#ifndef CONFIG_LITTLEFS_USE_ONLY_HASH
939+
ESP_LOGV(TAG, "Failed to sync at opening file \"%s\". Error %s (%d)",
940+
file->path, esp_littlefs_errno(res), res);
941+
#else
942+
ESP_LOGV(TAG, "Failed to sync at opening file %d. Error %d", fd, res);
943+
#endif
944+
}
945+
930946
file->hash = compute_hash(path);
931947
#ifndef CONFIG_LITTLEFS_USE_ONLY_HASH
932948
memcpy(file->path, path, path_len);

0 commit comments

Comments
 (0)