fs.watch 在 Mac OSX 上通过 Node 0.5.9
我在 Node v0.5.9 上运行以下命令:
var fs = require("fs");
fs.watch("/Users/username/testingFsWatcher/",function(event,file) {
console.dir(arguments);
});
然后执行以下操作:
cd /Users/username/testingFsWatcher/
>file1
-->{ '0': '重命名', '1': null }
mkdir new_folder
-->{ '0': '重命名', '1': null }
>new_folder/file2
-->没有事件触发/输出touch file1
-->没有事件触发/输出rm file1
-->{ '0': 'rename', '1': null }
我注意到有两件事似乎不正确:不监视子目录 (new_folder
) 以及监视更新/修改文件不会触发 change
事件。查看节点代码并进行测试,似乎这些应该是可能的。
那么,是否可以使用 fs.watch
来监视一个目录及其所有子目录?是否至少可以从文件修改中获取事件?另外,据我所知,fs.watch
由 kqueue
支持,它与 eventid
绑定(在 OSX 中),是否可能获取该 eventid
?
注意:我专门使用 fs.watch
而不是 fs.watchFile
因为我需要监视整个目录(最好也是它的所有子目录:)。
感谢您的帮助!
I'm running the following on Node v0.5.9:
var fs = require("fs");
fs.watch("/Users/username/testingFsWatcher/",function(event,file) {
console.dir(arguments);
});
I then do:
cd /Users/username/testingFsWatcher/
>file1
-->{ '0': 'rename', '1': null }
mkdir new_folder
-->{ '0': 'rename', '1': null }
>new_folder/file2
--> no event triggered/outputtouch file1
--> no event triggered/outputrm file1
-->{ '0': 'rename', '1': null }
Two things I noticed that seem incorrect: subdirectories (new_folder
) are not watched and updates/modifications to watched files do not trigger a change
event. Looking over the node code and tests it seems like these should be possible.
So, is it possible to get fs.watch
to watch a directory and all of it's subdirectories? Is it at least possible to get an event from a file modification? Also, from what I can tell, fs.watch
is backed by kqueue
which is tied to an eventid
(in OSX), is it possible to get that eventid
?
Note: I'm specifically using fs.watch
and not fs.watchFile
because I need to watch an entire directory (preferably all of it's subdirectories too :).
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题在最新的 Node 版本中不再出现。但是,
fs.watch
中还存在其他几个错误,因此您可能需要推迟使用它,直到这些错误得到解决:https://github.com/joyent/node/issues/search?q=fs.watchThis problem no longer appears in the latest Node release. However, there are several other remaining bugs in
fs.watch
, so you may want to hold off on using it until those are addressed: https://github.com/joyent/node/issues/search?q=fs.watch