From 0284917c8220726c0f5f39955ec7ae1c18fb617d Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 17 Oct 2018 17:21:49 +0700 Subject: [PATCH] update file close() to support directory --- libraries/FileSystem/src/FileIO.cpp | 2 +- libraries/FileSystem/src/FileIO.h | 2 +- libraries/FileSystem/src/InternalFS.cpp | 11 +++++++++-- libraries/FileSystem/src/InternalFS.h | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libraries/FileSystem/src/FileIO.cpp b/libraries/FileSystem/src/FileIO.cpp index 728d46f3..cf2c1df6 100644 --- a/libraries/FileSystem/src/FileIO.cpp +++ b/libraries/FileSystem/src/FileIO.cpp @@ -124,7 +124,7 @@ void File::close (void) { if ( _hdl ) { - _fs->_f_close(_hdl); + _fs->_f_close(_hdl, _is_dir); rtos_free(_hdl); } diff --git a/libraries/FileSystem/src/FileIO.h b/libraries/FileSystem/src/FileIO.h index 863ffa56..2f35be5c 100644 --- a/libraries/FileSystem/src/FileIO.h +++ b/libraries/FileSystem/src/FileIO.h @@ -116,7 +116,7 @@ class FileSystemClass virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size) = 0; virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte) = 0; virtual void _f_flush (void* fhdl) = 0; - virtual void _f_close (void* fhdl) = 0; + virtual void _f_close (void* fhdl, bool is_dir) = 0; virtual bool _f_seek (void* fhdl, uint32_t pos) = 0; virtual uint32_t _f_position (void* fhdl) = 0; diff --git a/libraries/FileSystem/src/InternalFS.cpp b/libraries/FileSystem/src/InternalFS.cpp index c091ca07..2ef4f089 100644 --- a/libraries/FileSystem/src/InternalFS.cpp +++ b/libraries/FileSystem/src/InternalFS.cpp @@ -308,9 +308,16 @@ uint32_t LittleFS::_f_size (void* fhdl) return lfs_file_size(&_lfs, (lfs_file_t*) fhdl); } -void LittleFS::_f_close (void* fhdl) +void LittleFS::_f_close (void* fhdl, bool is_dir) { - lfs_file_close(&_lfs, (lfs_file_t*) fhdl); + if ( is_dir ) + { + lfs_dir_close(&_lfs, (lfs_dir_t *) fhdl); + } + else + { + lfs_file_close(&_lfs, (lfs_file_t*) fhdl); + } } File LittleFS::_f_openNextFile (void* fhdl, uint8_t mode) diff --git a/libraries/FileSystem/src/InternalFS.h b/libraries/FileSystem/src/InternalFS.h index 3b63dfd9..57b6f6b2 100644 --- a/libraries/FileSystem/src/InternalFS.h +++ b/libraries/FileSystem/src/InternalFS.h @@ -59,7 +59,7 @@ class LittleFS: public BluefuritLib::FileSystemClass virtual size_t _f_write (void* fhdl, uint8_t const *buf, size_t size); virtual int _f_read (void* fhdl, void *buf, uint16_t nbyte); virtual void _f_flush (void* fhdl); - virtual void _f_close (void* fhdl); + virtual void _f_close (void* fhdl, bool is_dir); virtual bool _f_seek (void* fhdl, uint32_t pos); virtual uint32_t _f_position (void* fhdl); virtual uint32_t _f_size (void* fhdl);