1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

Filesystem: fix File::available, add File::name

This commit is contained in:
Ivan Grokhotkov
2015-08-05 07:41:12 -04:00
parent 90efba073f
commit b5d9db91aa
4 changed files with 19 additions and 3 deletions

View File

@ -41,7 +41,7 @@ int File::available() {
if (!_p)
return false;
return _p->position() < _p->size();
return _p->size() - _p->position();
}
int File::read() {
@ -112,6 +112,13 @@ File::operator bool() const {
return !!_p;
}
const char* File::name() const {
if (!_p)
return nullptr;
return _p->name();
}
File Dir::openFile(const char* mode) {
if (!_impl) {
return File();

View File

@ -64,6 +64,7 @@ public:
size_t size() const;
void close();
operator bool() const;
const char* name() const;
protected:
FileImplPtr _p;

View File

@ -33,6 +33,7 @@ public:
virtual size_t position() const = 0;
virtual size_t size() const = 0;
virtual void close() = 0;
virtual const char* name() const = 0;
};
enum OpenMode {

View File

@ -259,6 +259,12 @@ public:
DEBUGV("SPIFFS_close: fd=%d\r\n", _fd);
}
const char* name() const override {
CHECKFD();
return (const char*) _stat.name;
}
protected:
SPIFFSImpl* _fs;
spiffs_file _fd;
@ -283,10 +289,11 @@ public:
return FileImplPtr();
}
int mode = getSpiffsMode(openMode, accessMode);
spiffs_file fd = SPIFFS_open_by_dirent(_fs->getFs(), &_dirent, mode, 0);
auto fs = _fs->getFs();
spiffs_file fd = SPIFFS_open_by_dirent(fs, &_dirent, mode, 0);
if (fd < 0) {
DEBUGV("SPIFFSDirImpl::openFile: fd=%d path=`%s` openMode=%d accessMode=%d err=%d\r\n",
fd, _dirent.name, openMode, accessMode, _fs.err_code);
fd, _dirent.name, openMode, accessMode, fs->err_code);
return FileImplPtr();
}
return std::make_shared<SPIFFSFileImpl>(_fs, fd);