From ebc29380ca31c872329c30fc06ef73e9868beaf5 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Thu, 18 Apr 2024 13:25:59 -0700 Subject: [PATCH] Add creation timestamp to LittleFS directories Partial fix #9120. This is simple enough to include and does not increase the amount of flash writes on file updates significantly (which a modified-time 't' attribute would). --- libraries/LittleFS/src/LittleFS.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/LittleFS/src/LittleFS.h b/libraries/LittleFS/src/LittleFS.h index a3afbfe77f..ebdcdbcb9e 100644 --- a/libraries/LittleFS/src/LittleFS.h +++ b/libraries/LittleFS/src/LittleFS.h @@ -167,6 +167,14 @@ class LittleFSImpl : public FSImpl return false; } int rc = lfs_mkdir(&_lfs, path); + if ((rc == 0) && _timeCallback) { + time_t now = _timeCallback(); + // Add metadata with creation time to the directory marker + int rc = lfs_setattr(_fs->getFS(), path, 'c', (const void *)&now, sizeof(now)); + if (rc < 0) { + DEBUGV("Unable to set last write time on '%s' to %ld\n", path, (long)now); + } + } return (rc==0); }