如何在TCL中设置符号链接的mtime?

问题描述

file mtime可用于设置文件修改时间。但是,如果这是一个符号链接,它将设置目标的mtime。如何设置符号链接本身的mtime?

解决方法

到目前为止,最简单的方法是运行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]
}

这是因为Tcl不提供对utimensat(2)系统调用(或其包装,lutimes(3))的任何本机访问。您可以在Tcl扩展中(直接或使用Critcl或SWIG)创建自己的访问功能,但是对于偶尔设置单个链接的情况,使用touch选项调出到-h最简单。 / p>