mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Check file path when doing SPIFFS_readdir (#746)
SPIFFS is actually a flat file system, so opendir/readdir always iterate over all files. This adds explicit check that file name returned after readdir starts with the requested pattern.
This commit is contained in:
parent
a9d4e6c3e6
commit
cd9791eebe
@ -318,8 +318,9 @@ protected:
|
|||||||
|
|
||||||
class SPIFFSDirImpl : public DirImpl {
|
class SPIFFSDirImpl : public DirImpl {
|
||||||
public:
|
public:
|
||||||
SPIFFSDirImpl(SPIFFSImpl* fs, spiffs_DIR& dir)
|
SPIFFSDirImpl(const String& pattern, SPIFFSImpl* fs, spiffs_DIR& dir)
|
||||||
: _fs(fs)
|
: _pattern(pattern)
|
||||||
|
, _fs(fs)
|
||||||
, _dir(dir)
|
, _dir(dir)
|
||||||
, _valid(false)
|
, _valid(false)
|
||||||
{
|
{
|
||||||
@ -359,12 +360,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool next() override {
|
bool next() override {
|
||||||
|
const int n = _pattern.length();
|
||||||
|
do {
|
||||||
spiffs_dirent* result = SPIFFS_readdir(&_dir, &_dirent);
|
spiffs_dirent* result = SPIFFS_readdir(&_dir, &_dirent);
|
||||||
_valid = (result != nullptr);
|
_valid = (result != nullptr);
|
||||||
|
} while(_valid && strncmp((const char*) _dirent.name, _pattern.c_str(), n) != 0);
|
||||||
return _valid;
|
return _valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
String _pattern;
|
||||||
SPIFFSImpl* _fs;
|
SPIFFSImpl* _fs;
|
||||||
spiffs_DIR _dir;
|
spiffs_DIR _dir;
|
||||||
spiffs_dirent _dirent;
|
spiffs_dirent _dirent;
|
||||||
@ -394,7 +399,7 @@ DirImplPtr SPIFFSImpl::openDir(const char* path) {
|
|||||||
DEBUGV("SPIFFSImpl::openDir: path=`%s` err=%d\r\n", path, _fs.err_code);
|
DEBUGV("SPIFFSImpl::openDir: path=`%s` err=%d\r\n", path, _fs.err_code);
|
||||||
return DirImplPtr();
|
return DirImplPtr();
|
||||||
}
|
}
|
||||||
return std::make_shared<SPIFFSDirImpl>(this, dir);
|
return std::make_shared<SPIFFSDirImpl>(path, this, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSpiffsMode(OpenMode openMode, AccessMode accessMode) {
|
int getSpiffsMode(OpenMode openMode, AccessMode accessMode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user