1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Only update LittleFS timestamp when opened write (#6956)

Fixes #6955

LittleFS was updating the timestamp on any close, not only for files
when they were opened for writing.  This could lead to excessive writes
to the flash.

Preserve the LFS flags, and only update the timestamp if the file was
opened for writing.
This commit is contained in:
Earle F. Philhower, III
2019-12-30 15:43:26 -08:00
committed by GitHub
parent 2492043669
commit fa5040d5da
2 changed files with 5 additions and 4 deletions

View File

@ -323,7 +323,7 @@ protected:
class LittleFSFileImpl : public FileImpl
{
public:
LittleFSFileImpl(LittleFSImpl* fs, const char *name, std::shared_ptr<lfs_file_t> fd) : _fs(fs), _fd(fd), _opened(true) {
LittleFSFileImpl(LittleFSImpl* fs, const char *name, std::shared_ptr<lfs_file_t> fd, int flags) : _fs(fs), _fd(fd), _opened(true), _flags(flags) {
_name = std::shared_ptr<char>(new char[strlen(name) + 1], std::default_delete<char[]>());
strcpy(_name.get(), name);
}
@ -419,7 +419,7 @@ public:
lfs_file_close(_fs->getFS(), _getFD());
_opened = false;
DEBUGV("lfs_file_close: fd=%p\n", _getFD());
if (timeCallback) {
if (timeCallback && (_flags & LFS_O_WRONLY)) {
// Add metadata with last write time
time_t now = timeCallback();
int rc = lfs_setattr(_fs->getFS(), _name.get(), 't', (const void *)&now, sizeof(now));
@ -483,6 +483,7 @@ protected:
std::shared_ptr<lfs_file_t> _fd;
std::shared_ptr<char> _name;
bool _opened;
int _flags;
};
class LittleFSDirImpl : public DirImpl