Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow attribute get on root #7873

Merged
merged 4 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cores/esp8266/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ bool FS::rename(const String& pathFrom, const String& pathTo) {
return rename(pathFrom.c_str(), pathTo.c_str());
}

time_t FS::getCreationTime() {
if (!_impl) {
return 0;
}
return _impl->getCreationTime();
}

void FS::setTimeCallback(time_t (*cb)(void)) {
if (!_impl)
return;
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class FS
bool gc();
bool check();

time_t getCreationTime();

void setTimeCallback(time_t (*cb)(void));

friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/FSImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class FSImpl {
virtual bool rmdir(const char* path) = 0;
virtual bool gc() { return true; } // May not be implemented in all file systems.
virtual bool check() { return true; } // May not be implemented in all file systems.
virtual time_t getCreationTime() { return 0; } // May not be implemented in all file systems.

// Filesystems *may* support a timestamp per-file, so allow the user to override with
// their own callback for all files on this FS. The default implementation simply
Expand Down
33 changes: 33 additions & 0 deletions libraries/LittleFS/src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,46 @@ class LittleFSImpl : public FSImpl
return false;
}

if(_timeCallback && _tryMount()) {
// Mounting is required to set attributes

time_t t = _timeCallback();
rc = lfs_setattr(&_lfs, "/", 'c', &t, 8);
if (rc != 0) {
DEBUGV("lfs_format, lfs_setattr 'c': rc=%d\n", rc);
return false;
}

rc = lfs_setattr(&_lfs, "/", 't', &t, 8);
if (rc != 0) {
DEBUGV("lfs_format, lfs_setattr 't': rc=%d\n", rc);
return false;
}

lfs_unmount(&_lfs);
_mounted = false;
}

if (wasMounted) {
return _tryMount();
}

return true;
}

time_t getCreationTime() override {
time_t t;
uint32_t t32b;

if (lfs_getattr(&_lfs, "/", 'c', &t, 8) == 8) {
return t;
} else if (lfs_getattr(&_lfs, "/", 'c', &t32b, 4) == 4) {
return (time_t)t32b;
} else {
return 0;
}
}


protected:
friend class LittleFSFileImpl;
Expand Down