开发者

fs.watch via Node 0.5.9 on Mac OSX

开发者 https://www.devze.com 2023-04-13 02:01 出处:网络
I\'m running the following on Node v0.5.9: var fs = require(\"fs\"); fs.watch(\"/Users/username/testingFsWatcher/\",function(event,file) {

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/output
  • touch file1 --> no event triggered/output
  • rm 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!


This 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号