web: the host build no longer deletes images outside its data directory

The host's file layer (web/compat/arduino/vfs_api.cpp) passed readdir()'s
"." and ".." entries through openNextFile() and getNextFileName(). No ESP32
file system returns them, so the firmware's directory walkers do not expect
them, and the boot SPIFFS image purge in UITask::begin() queued "/.." as a
folder and walked up out of <data>/spiffs, deleting every *.png and *.jpg it
reached around the data directory (seen: all screenshots in sibling folders
of a scripted run's data dir were gone after the next run). Both entries are
now skipped, as on the device. Checked with a fresh data dir between marker
files: the markers outside survive, a tile image inside spiffs/ is still
purged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaj SchittecatandClaude Opus 5.5 committed 2026-10-26 13:42:14 +01:00
1 parent 882a2046cf
commit af03d890e0
1 file changed
+17 -3
+17 -3
View File
@@ -491,12 +491,26 @@ boolean VFSFileImpl::isDirectory(void)
return _isDirectory;
}
// Host only: a POSIX readdir() lists "." and "..", which no ESP32 VFS (SPIFFS, LittleFS, FAT)
// ever returns. The firmware's directory walkers (the boot SPIFFS image purge among them) then
// descended "/.." out of the data directory and deleted *.png / *.jpg files around it. Skip both,
// as the device file systems do.
static struct dirent* readdirNoDots(DIR* d)
{
struct dirent* e;
while ((e = readdir(d)) != NULL) {
if (e->d_name[0] == '.' && (e->d_name[1] == '\0' || (e->d_name[1] == '.' && e->d_name[2] == '\0'))) continue;
return e;
}
return NULL;
}
FileImplPtr VFSFileImpl::openNextFile(const char* mode)
{
if(!_isDirectory || !_d) {
return FileImplPtr();
}
struct dirent *file = readdir(_d);
struct dirent *file = readdirNoDots(_d);
if(file == NULL) {
return FileImplPtr();
}
@@ -540,7 +554,7 @@ String VFSFileImpl::getNextFileName()
if (!_isDirectory || !_d) {
return "";
}
struct dirent *file = readdir(_d);
struct dirent *file = readdirNoDots(_d);
if (file == NULL) {
return "";
}
@@ -561,7 +575,7 @@ String VFSFileImpl::getNextFileName(bool *isDir)
if (!_isDirectory || !_d) {
return "";
}
struct dirent *file = readdir(_d);
struct dirent *file = readdirNoDots(_d);
if (file == NULL) {
return "";
}