Lars Brinkhoff
Lars Brinkhoff

Reputation: 14315

How do I set the mtime of a symlink in TCL?

file mtime can be used to set the modifcation time of a file. But if it's a symlink, it will set the mtime of the target. How do I set the mtime of the symlink itself?

Upvotes: 1

Views: 144

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137707

By far the easiest approach will be to run an external command:

proc SetMtime {filename timestamp} {
    # A little bit of type enforcement; it's not necessary, but avoids potential trouble
    exec touch -h -t [expr {int($timestamp)}] [file normalize $filename]
}

This is because Tcl does not provide any native access to the utimensat(2) system call (or its wrapper, lutimes(3)). You could make your own access functions in a Tcl extension (either directly, or using Critcl or SWIG) but for just setting a single link occasionally, calling out to touch with the -h option is easiest.

Upvotes: 2

Related Questions