Problem on Linux:
When trying to set the date (mtime) of an file f,
from owner y by user x, who as writing permissions, via:
import std.datetime;
auto time = Clock.currTime();
setTimes(f,time,time);
You get "Operation not permitted."
This is caused on linux by the rule, that if you are not the owner of the file
you may only set the mtime of a file to current time.
Which could not be achieved when calling
setTimes(f, Clock.currTime(),Clock.currTime());
So a function touch(f), which ensures this behavior would be useful.
The work around in the moment is to use execute("touch ~"filename").
Not the right for a system programming language :-(
Comment #1 by dlang-bugzilla — 2017-07-26T09:44:32Z
The way to do this on Linux is to call utime(fileName, null).
(In reply to Martin Tschierschke from comment #0)
> The work around in the moment is to use execute("touch ~"filename").
> Not the right for a system programming language :-(
I think this is simpler:
utimes(fileName.toStringz, *cast(timeval[2]*)null);
Not sure whether this is something that comes up frequently enough to be in Phobos, especially considering it seems rather platform-specific. The name "touch" carries with it the possible implication that non-existing files will be created (as done by the program), which might not be desirable for a Phobos function.
Comment #2 by schveiguy — 2017-07-26T11:28:34Z
I think a function setTimes(filename) or setTimesCurrent(filename) would be a useful addition.
The setTimes function is cross platform and so is handy to use in platform agnostic code. It would be nice to have support for this in there somehow.
Comment #3 by robert.schadek — 2024-12-01T16:30:37Z