From e151d5b7476def869a0e112d1ead4b750fdf4e90 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 11:43:45 -0600 Subject: [PATCH 1/8] rmdir causes issues in SPIFFS. Fixes #4138, albeit not very cleanly --- libraries/FS/src/vfs_api.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 6502f760560..5fd51748afa 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -183,13 +183,16 @@ bool VFSImpl::rmdir(const char *path) log_e("File system is not mounted"); return false; } - VFSFileImpl f(this, path, "r"); - if(!f || !f.isDirectory()) { + if(!f || !f.isDirectory() || _mountpoint == "/spiffs") { + if (_mountpoint == "/spiffs") { + log_e("rmdir is unnecessary in SPIFFS"); + } else { + log_e("%s does not exists or is a file", path); + } if(f) { f.close(); } - log_e("%s does not exists or is a file", path); return false; } f.close(); @@ -200,7 +203,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; } From 9f8794acd219c94026e3de2d8aab62b1ffd89d9b Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 15:54:53 -0600 Subject: [PATCH 2/8] don't string literal comparison --- libraries/FS/src/vfs_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 5fd51748afa..dc7cd81a680 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -184,8 +184,8 @@ bool VFSImpl::rmdir(const char *path) return false; } VFSFileImpl f(this, path, "r"); - if(!f || !f.isDirectory() || _mountpoint == "/spiffs") { - if (_mountpoint == "/spiffs") { + if(!f || !f.isDirectory() || strcmp(_mountpoint, "/spiffs") == 0) { + if (strcmp(_mountpoint, "/spiffs") == 0) { log_e("rmdir is unnecessary in SPIFFS"); } else { log_e("%s does not exists or is a file", path); From da0861f2d88b707e47d4187dc6e705c031a9e9a3 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 16:04:18 -0600 Subject: [PATCH 3/8] lost a CR somewhere --- libraries/FS/src/vfs_api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index dc7cd81a680..cb9269228fe 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -183,6 +183,7 @@ bool VFSImpl::rmdir(const char *path) log_e("File system is not mounted"); return false; } + VFSFileImpl f(this, path, "r"); if(!f || !f.isDirectory() || strcmp(_mountpoint, "/spiffs") == 0) { if (strcmp(_mountpoint, "/spiffs") == 0) { From b8db69f69ee663c5e5583a198433018742c180d9 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 17:13:00 -0600 Subject: [PATCH 4/8] function name overlap- needs to use the exfun! --- libraries/FS/src/vfs_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index cb9269228fe..1c207729944 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -204,7 +204,7 @@ bool VFSImpl::rmdir(const char *path) return false; } sprintf(temp,"%s%s", _mountpoint, path); - auto rc = rmdir(temp); + auto rc = ::rmdir(temp); free(temp); return rc == 0; } From 8723b6ddb93787a4b77fe55dd98191a98db155c3 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 17:39:04 -0600 Subject: [PATCH 5/8] Don't even bother opening the file if on spiffs --- libraries/FS/src/vfs_api.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 1c207729944..0211c29c6c8 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -184,13 +184,14 @@ 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() || strcmp(_mountpoint, "/spiffs") == 0) { - if (strcmp(_mountpoint, "/spiffs") == 0) { - log_e("rmdir is unnecessary in SPIFFS"); - } else { - log_e("%s does not exists or is a file", path); - } + log_e("%s does not exists or is a file", path); if(f) { f.close(); } From db8ec104fd9d497b8be108ce8870dd340fb3fb1f Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 17:49:35 -0600 Subject: [PATCH 6/8] missed some cleanup --- libraries/FS/src/vfs_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 0211c29c6c8..119e258a571 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -190,7 +190,7 @@ bool VFSImpl::rmdir(const char *path) } VFSFileImpl f(this, path, "r"); - if(!f || !f.isDirectory() || strcmp(_mountpoint, "/spiffs") == 0) { + if(!f || !f.isDirectory()) == 0) { log_e("%s does not exists or is a file", path); if(f) { f.close(); From e4c2511f47de6095d0ee63678cdaa3133b6700b0 Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 17:50:40 -0600 Subject: [PATCH 7/8] really, this time --- libraries/FS/src/vfs_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 119e258a571..90dfce5ca55 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -190,7 +190,7 @@ bool VFSImpl::rmdir(const char *path) } VFSFileImpl f(this, path, "r"); - if(!f || !f.isDirectory()) == 0) { + if(!f || !f.isDirectory()) { log_e("%s does not exists or is a file", path); if(f) { f.close(); From 9986315bf3c8b432ed1c427a6b69d4cd1c42930d Mon Sep 17 00:00:00 2001 From: Larry Bernstone Date: Fri, 10 Jul 2020 17:52:15 -0600 Subject: [PATCH 8/8] move things back to where they were --- libraries/FS/src/vfs_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/FS/src/vfs_api.cpp b/libraries/FS/src/vfs_api.cpp index 90dfce5ca55..346b7a93248 100644 --- a/libraries/FS/src/vfs_api.cpp +++ b/libraries/FS/src/vfs_api.cpp @@ -191,10 +191,10 @@ bool VFSImpl::rmdir(const char *path) VFSFileImpl f(this, path, "r"); if(!f || !f.isDirectory()) { - log_e("%s does not exists or is a file", path); if(f) { f.close(); } + log_e("%s does not exists or is a file", path); return false; } f.close();