rmdir causes issues in SPIFFS. Fixes #4138, albeit not very cleanly (#4154)

SPIFFS causes crashes if you attempt to rmdir. Since there are no true directories in spiffs, this ought to be a noop. It looks like @me-no-dev worked around this by using unlink instead of rmdir, which works in fatfs and doesn't panic spiffs. This behavior is not universal. In order to get littlefs working, it would be good to get this back to conformity. Rather than digging deep into the upstream spiffs, I just check the mountpoint and noop if it is "/spiffs". So, if the user has changed the mountpoint, this will not work, but I think it's a pretty good tradeoff.
This commit is contained in:
lbernstone 2020-10-01 04:52:24 -06:00 committed by GitHub
parent 93d850f783
commit 882b12c44e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,6 +184,11 @@ bool VFSImpl::rmdir(const char *path)
return false; return false;
} }
if (strcmp(_mountpoint, "/spiffs") == 0) {
log_e("rmdir is unnecessary in SPIFFS");
return false;
}
VFSFileImpl f(this, path, "r"); VFSFileImpl f(this, path, "r");
if(!f || !f.isDirectory()) { if(!f || !f.isDirectory()) {
if(f) { if(f) {
@ -200,7 +205,7 @@ bool VFSImpl::rmdir(const char *path)
return false; return false;
} }
sprintf(temp,"%s%s", _mountpoint, path); sprintf(temp,"%s%s", _mountpoint, path);
auto rc = unlink(temp); auto rc = ::rmdir(temp);
free(temp); free(temp);
return rc == 0; return rc == 0;
} }