nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.62k stars 3.12k forks source link

Fix file.list() zero sizes #3554

Closed tomsci closed 1 year ago

tomsci commented 1 year ago

Fixes #3549

The modern spiffs backend doesn't like stat("./somefile") for something on the root of the filesystem, and instead only accepts "somefile" (it also doesn't like "/somefile"). The error from stat was being ignored which is why the file sizes all appeared to be zero. I don't know why spiffs is so picky... mumbles something about mount points.

The fix is to change file.list() to pass just the filename into the stat() call, unless a directory was passed to list() in which case do what we used to do and prepend the dir name. Also improved error handling so we call closedir if we error. I also changed the opendir to open "/" rather than ".", but since we don't expose any way to change cwd I don't think it matters either way, but I felt it was a bit clearer to use "/".

Tested on esp32s2 with dev-esp32-idf4 @ d8f07ddf90a278abb77a5247d4ce34201de9e56d

serg3295 commented 1 year ago

I have tested this PR on ESP32 Devkitc_v4. file.list() now returns proper size both for files on spiffs and for files on mounted volumes of eromfs module. Thank you!