www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - howto touch a file - setTimes

reply Martin Tschierschke <mt smartdolphin.de> writes:
When I tried to set the atime and mtime of a file (f) via:

import std.datetime;
auto time = Clock.currTime();
setTimes(f,time,time);

I 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.

A simple "touch filename" in terminal works.

Any hint? Do I have to use execute("touch filename")?
Jul 24 2017
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/24/17 1:11 PM, Martin Tschierschke wrote:
 When I tried to set the atime and mtime of a file (f) via:
 
 import std.datetime;
 auto time = Clock.currTime();
 setTimes(f,time,time);
 
 I 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.
 
 A simple "touch filename" in terminal works.
 
 Any hint? Do I have to use execute("touch filename")?
Hm... looking at the man page, it appears that you need to call the system call (e.g. utimes) with a null array. This isn't possible via the current API. You could call it yourself instead of executing touch. Would be a good enhancement request, please file: https://issues.dlang.org -Steve
Jul 24 2017