From 882b12c44e9aca640a8adad16c11cd41c67e0f7b Mon Sep 17 00:00:00 2001 From: lbernstone Date: Thu, 1 Oct 2020 04:52:24 -0600 Subject: [PATCH] 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. --- libraries/FS/src/vfs_api.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 6502f760..346b7a93 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -184,6 +184,11 @@ bool VFSImpl::rmdir(const char *path) return false; } + if (strcmp(_mountpoint, "/spiffs") == 0) { + log_e("rmdir is unnecessary in SPIFFS"); + return false; + } + VFSFileImpl f(this, path, "r"); if(!f || !f.isDirectory()) { if(f) { @@ -200,7 +205,7 @@ bool VFSImpl::rmdir(const char *path) return false; } sprintf(temp,"%s%s", _mountpoint, path); - auto rc = unlink(temp); + auto rc = ::rmdir(temp); free(temp); return rc == 0; }