diff --git a/libraries/FileSystem/src/FileIO.cpp b/libraries/FileSystem/src/FileIO.cpp index ae684960..47604526 100644 --- a/libraries/FileSystem/src/FileIO.cpp +++ b/libraries/FileSystem/src/FileIO.cpp @@ -44,6 +44,7 @@ File::File (FileSystemClass &fs) { _fs = &fs; _hdl = NULL; + _name = NULL; _is_dir = false; } @@ -51,7 +52,9 @@ File::File (char const *filename, uint8_t mode, FileSystemClass &fs) { _fs = &fs; _hdl = NULL; + _name = NULL; _is_dir = false; + open(filename, mode); } @@ -62,7 +65,7 @@ File::~File () bool File::open (char const *filename, uint8_t mode) { - // close previous opened + // close if currently opened if ( _hdl ) close(); *this = _fs->open(filename, mode); @@ -130,7 +133,10 @@ void File::close (void) rtos_free(_hdl); } + if ( _name ) rtos_free(_name); + _hdl = NULL; + _name = NULL; } File::operator bool () @@ -138,9 +144,9 @@ File::operator bool () return _hdl != NULL; } -char const * File::name (void) +const char* File::name (void) { - + return _name; } bool File::isDirectory (void) diff --git a/libraries/FileSystem/src/FileIO.h b/libraries/FileSystem/src/FileIO.h index 2f35be5c..3c2a4e4a 100644 --- a/libraries/FileSystem/src/FileIO.h +++ b/libraries/FileSystem/src/FileIO.h @@ -37,6 +37,8 @@ #define FILE_WRITE 1 #define FILE_APPEND 2 +#define FILE_NAME_MAX 255 + class LittleFS; namespace BluefuritLib @@ -69,7 +71,7 @@ class File: public Stream void close (void); operator bool (void); - char const * name (void); + const char* name (void); bool isDirectory (void); File openNextFile (uint8_t mode = FILE_READ); @@ -80,10 +82,9 @@ class File: public Stream private: FileSystemClass* _fs; void* _hdl; + char* _name; bool _is_dir; -// String filename; - friend class ::LittleFS; }; diff --git a/libraries/FileSystem/src/InternalFS.cpp b/libraries/FileSystem/src/InternalFS.cpp index e7d74612..f530742e 100644 --- a/libraries/FileSystem/src/InternalFS.cpp +++ b/libraries/FileSystem/src/InternalFS.cpp @@ -35,6 +35,7 @@ /**************************************************************************/ #include +#include #include "InternalFS.h" #include "flash/flash_nrf52.h" @@ -238,6 +239,8 @@ BluefuritLib::File LittleFS::_openByInfo (struct lfs_info *info, uint8_t mode) { file._hdl = fhdl; file._is_dir = (info->type == LFS_TYPE_DIR); + file._name = (char*) rtos_malloc(strlen(info->name) + 1); + strcpy(file._name, info->name); } }