-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add time to filesystem API #6544
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
Conversation
Support the ESP32 File::getLastWrite() call and setting the time on all filesystems automatically (assuming the system clock has been set properly and time(NULL) returns the proper time!). Adds Dir::fileTime() to get the time of a file being listed, similar to Dir::fileName() and Dir::fileSize(). Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing users to override the default timestamp on a per-file, directory, or filesystem basis. By default, a simple callback returning time(nullptr) is implemented. LittleFS uses the 't' attribute and should be backwards compatible. SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks using the MSDOS time. This PR does not update SPIFFS, due to compatability concerns and a possible massive rewrite which would make it possible to determine if an old-style ot metadata enabled FS is present at mount time. Includes an updated SD/listfiles and LittleFS_time example. Replaces esp8266#6315
By removing the possibly data-corrupting changes required for SPIFFS time addition (see PR #6315), this PR should be able to be merged at 0 risk and pave the way for a future SPIFFS enhancement to include dynamic metadata and others (possibly w/the 3.0 partition table giving us the FS info as opposed to us manually poisoning things). |
Include the update mklittlefs which generated 't' metadata on imported files. ../tools/sdk/lwip2/include/netif/lowpan6_opts.h
eed2bc5
to
1ea5af4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'd add a note stating stored time is always local time for LittleFS
(like it's always been in msdos fat but not in modern FSes).
I understand the FS is using local time stamps. If so, how about using global time instead, like real platforms? That would disallow problems with changing timezone, changing DST, updating time manually, etc. |
As we discussed online, this is what we're stuck with for SDFS/SD, since FAT doesn't use UTC, only local time. It is possible, however, for users to override the setTimeCallback() to return UTC if they wish for LittleFS (or even FAT) and documented in the File section. |
Clean up some awkward object instantiations. Remove the _enableTime flag/setter from SPIFFS. Clean up the FSConfig constructors using C++ style init lists.
I couldn't find a good way to use the enum for FSId (each class' enum was a unique type so there were ugly casts), so I settled on a |
where is the function time(NULL) referred in FS.h? |
In |
Support the ESP32 File::getLastWrite() call and setting the time on
all filesystems automatically (assuming the system clock has
been set properly and time(NULL) returns the proper time!).
Adds Dir::fileTime() to get the time of a file being listed, similar to
Dir::fileName() and Dir::fileSize().
Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing
users to override the default timestamp on a per-file, directory, or
filesystem basis. By default, a simple callback returning time(nullptr)
is implemented.
LittleFS uses the 't' attribute and should be backwards compatible.
SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks
using the MSDOS time.
This PR does not update SPIFFS, due to compatability concerns and a
possible massive rewrite which would make it possible to determine if an
old-style ot metadata enabled FS is present at mount time.
Includes an updated SD/listfiles and LittleFS_time example.
Replaces #6315