← index #2762PR #9644
Duplicate · high · value 0.461
QUERY · ISSUE

os.utime is missing

openby zsquarepluscopened 2017-01-05updated 2024-09-29
enhancementneeds-info

When writing file sync tools, it would be nice if the files put on a micropython board could be updated with their original timestamp (via os.utime). So sync tools could check the file date to determine if a file needs to be changed or is already up-to-date. (A more precise check can be made with actually inspecting the file contents, but for simple and quick syncs, the date is preferable).

Currently it is only possible to create new files that will get the "current time" which is a more or less random value near 1970 or 1985, as the clocks of those boards are usually not set and not battery backed up.

I see the FAT driver already has a f_utime() function, so adding this one should be easy (I might provide a pull request with a basic implementation e.g. times in seconds not ns, if desired).

CANDIDATE · PULL REQUEST

moduos: Add os.utime() support to vfs layer and LFS2, FAT and posix filesystems.

openby glenn20opened 2022-10-17updated 2024-03-07
extmod

This PR adds support for os.utime(filename, (atime, mtime)).

This is especially useful for preserving timestamps of files and directory stuctures copied onto (or sunchronised) between micropython boards and host systems or for managing file timestamps.

Support is provided for LittleFS2, FAT and posix filesystems.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied