【发布时间】:2012-03-10 23:50:29
【问题描述】:
我正在尝试使用以下代码监视使用 node.js 的 watchFile() 进行(软)符号链接的文件:
var fs=require('fs')
, file= './somesymlink'
, config= {persist:true, interval:1};
fs.watchFile(file, config, function(curr, prev) {
if((curr.mtime+'')!=(prev.mtime+'')) {
console.log( file+' changed');
}
});
在上面的代码中,./somesymlink 是到 /path/to/the/actual/file 的(软)符号链接。 当对 /path/to/the/actual/file 进行更改时,不会触发任何事件。我必须用 /path/to/the/actual/file 替换符号链接才能使其工作。在我看来,watchFile 无法观看符号链接的文件。当然,我可以使用 spawn+tail 方法来完成这项工作,但我不喜欢使用该路径,因为它会引入更多开销。
所以我的问题是如何使用 watchFile() 在 node.js 中观看符号链接的文件。提前谢谢大家。
【问题讨论】:
标签: node.js