Unverified Commit 04693c66 authored by Lucas Machado's avatar Lucas Machado Committed by GitHub

Implements seekDir and getNextFileName on FS Lib to improve performance (#7229)

* Implements seekDir and getNextFileName on FS lib to improve performance
* getNextFileName return String directly
parent 90067516
......@@ -187,6 +187,22 @@ File File::openNextFile(const char* mode)
return _p->openNextFile(mode);
}
boolean File::seekDir(long position){
if(!_p){
return false;
}
return _p->seekDir(position);
}
String File::getNextFileName(void)
{
if (!_p) {
return "";
}
return _p->getNextFileName();
}
void File::rewindDirectory(void)
{
if (!*this) {
......
......@@ -78,7 +78,9 @@ public:
const char* name() const;
boolean isDirectory(void);
boolean seekDir(long position);
File openNextFile(const char* mode = FILE_READ);
String getNextFileName(void);
void rewindDirectory(void);
protected:
......
......@@ -43,6 +43,8 @@ public:
virtual const char* name() const = 0;
virtual boolean isDirectory(void) = 0;
virtual FileImplPtr openNextFile(const char* mode) = 0;
virtual boolean seekDir(long position);
virtual String getNextFileName(void);
virtual void rewindDirectory(void) = 0;
virtual operator bool() = 0;
};
......
......@@ -476,6 +476,36 @@ FileImplPtr VFSFileImpl::openNextFile(const char* mode)
return std::make_shared<VFSFileImpl>(_fs, name.c_str(), mode);
}
boolean VFSFileImpl::seekDir(long position){
if(!_d){
return false;
}
seekdir(_d, position);
return true;
}
String VFSFileImpl::getNextFileName()
{
if (!_isDirectory || !_d) {
return "";
}
struct dirent *file = readdir(_d);
if (file == NULL) {
return "";
}
if (file->d_type != DT_REG && file->d_type != DT_DIR) {
return "";
}
String fname = String(file->d_name);
String name = String(_path);
if (!fname.startsWith("/") && !name.endsWith("/")) {
name += "/";
}
name += fname;
return name;
}
void VFSFileImpl::rewindDirectory(void)
{
if(!_isDirectory || !_d) {
......
......@@ -71,6 +71,8 @@ public:
const char* name() const override;
time_t getLastWrite() override;
boolean isDirectory(void) override;
boolean seekDir(long position) override;
String getNextFileName(void) override;
FileImplPtr openNextFile(const char* mode) override;
void rewindDirectory(void) override;
operator bool();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment