Skip to content

Commit

Permalink
Add creation timestamp to LittleFS directories (esp8266#9127)
Browse files Browse the repository at this point in the history
* Add creation timestamp to LittleFS directories

Partial fix esp8266#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).

* Fix typo in debug message on error
  • Loading branch information
earlephilhower authored and hasenradball committed Nov 18, 2024
1 parent 1ccc65d commit 4ab0167
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libraries/LittleFS/src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(&_lfs, path, 'c', (const void *)&now, sizeof(now));
if (rc < 0) {
DEBUGV("Unable to set creation time on '%s' to %ld\n", path, (long)now);
}
}
return (rc==0);
}

Expand Down

0 comments on commit 4ab0167

Please sign in to comment.