Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Unix.utimes with 0.0 #6289
Original bug ID: 6289
The documentation says "A time of [0.0] is interpreted as the current time". However the implementation makes the test
which has two unfortunate consequences
Also, since the name is Unix.utimes and not Unix.utime, one should maybe prefer the utimes function (with its sub-second resolution) over the utime one when both are available.
Finally, one may also question the benefit of this convention. Maybe a function Unix.utimes_now would be a better replacement (Unix.utimes would thus have no exceptional behavior).
Comment author: @Chris00
That would mitigate the problem indeed. However, since in doing so you change the semantics of the function and you do not speak of using utimes (or utimensat) as the default, another solution would be to deprecate utimes and add utime, say with the following signature:
utime : string -> (float * float) option -> unit
utime : ?a: float -> ?m: float -> string -> unit
with the time being the current time if the argument is not set (this requires to call
Does this sound OK or is it too invasive?
Comment author: @damiendoligez
The problem with utimes (or more exotic functions like utimensat) is, as usual, portability. We try to rely only on POSIX-standard functions, and anything else needs to be auto-detected by the configure script.
If we make a new function, I'd rather go with your first one (an optional pair of floats) because it sticks with the interface of the underlying system call.
Also, I'm not convinced that the change in semantics is significant enough to warrant polluting the library with a deprecated function.
Comment author: talex
(author of the original blog post)
I'd also prefer the "(float * float) option" API to the optional arguments one, because I'd expect "utime ~a path" to set only the access time, not to set the mtime to the current time.
Just documenting that you can set the mtime to zero by setting the atime to something else would work for my use, though it's a bit ugly.