mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Rationalize File timestamp callback (#7785)
Fixes #7775 Clean up the passing/setting of custom File time callbacks and add a host test verifying they work. Existing core was not passing custom timeCallbacks set at the FS level down to open()ed files, resulting in them calling the default time(nullptr) and reporting wrong file modify times.
This commit is contained in:
committed by
GitHub
parent
f1dc6e90ee
commit
35d22edeec
@ -70,14 +70,14 @@ FileImplPtr LittleFSImpl::open(const char* path, OpenMode openMode, AccessMode a
|
||||
}
|
||||
|
||||
time_t creation = 0;
|
||||
if (timeCallback && (openMode & OM_CREATE)) {
|
||||
if (_timeCallback && (openMode & OM_CREATE)) {
|
||||
// O_CREATE means we *may* make the file, but not if it already exists.
|
||||
// See if it exists, and only if not update the creation time
|
||||
int rc = lfs_file_open(&_lfs, fd.get(), path, LFS_O_RDONLY);
|
||||
if (rc == 0) {
|
||||
lfs_file_close(&_lfs, fd.get()); // It exists, don't update create time
|
||||
} else {
|
||||
creation = timeCallback(); // File didn't exist or otherwise, so we're going to create this time
|
||||
creation = _timeCallback(); // File didn't exist or otherwise, so we're going to create this time
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ public:
|
||||
lfs_file_close(_fs->getFS(), _getFD());
|
||||
_opened = false;
|
||||
DEBUGV("lfs_file_close: fd=%p\n", _getFD());
|
||||
if (timeCallback && (_flags & LFS_O_WRONLY)) {
|
||||
if (_timeCallback && (_flags & LFS_O_WRONLY)) {
|
||||
// If the file opened with O_CREAT, write the creation time attribute
|
||||
if (_creation) {
|
||||
int rc = lfs_setattr(_fs->getFS(), _name.get(), 'c', (const void *)&_creation, sizeof(_creation));
|
||||
@ -433,7 +433,7 @@ public:
|
||||
}
|
||||
}
|
||||
// Add metadata with last write time
|
||||
time_t now = timeCallback();
|
||||
time_t now = _timeCallback();
|
||||
int rc = lfs_setattr(_fs->getFS(), _name.get(), 't', (const void *)&now, sizeof(now));
|
||||
if (rc < 0) {
|
||||
DEBUGV("Unable to set last write time on '%s' to %d\n", _name.get(), now);
|
||||
|
Reference in New Issue
Block a user