-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mac: fs.watch() not detecting changes to file from git operation #5039
Comments
chokidar is one solution from user-land. |
If the file gets deleted and immediately recreated, One workaround for this is to watch the parent directory of the file. Something like this: function watchFile(filepath, callback) {
var fpath = path.resolve(filepath),
fdir = path.dirname(fpath),
fname = path.basename(fpath);
fs.statSync(fdir);
return fs.watch(fdir, {persistent: false, recursive: false}, function (event, changed_fname) {
if (changed_fname === fname) {
fs.stat(fpath, function (err) {
callback && callback(null, !err, fpath);
});
}
});
} |
@bpasero I think @imyller's explanation is correct. It's not a bug or issue with It's just how paths and inodes work on OS X and Linux. The watch is actually watching the inode of the file and not the path of the file as far as I understand. The inode is resolved from the path of the file when the file is first watched. When the file is deleted, the watch remains on the inode of the deleted file. When the file is recreated by git it actually gets assigned a different inode, which is why changes to this file are no longer picked up by the watch (which is still watching the old deleted inode). One can confirm this by calling It would be better to have a recursive watch on the root of the file tree that you're interested in as @imyller suggested. This way you'll always pick up changes to children and descendants regardless of their inodes changing. It's also less resource intensive. |
Closing as this is not a bug. It may be worthwhile to have some more documentation around this, however. /cc @nodejs/documentation |
@jorangreef would you like to do a PR? |
@stevemao sure, working on it now. |
Done: #6099 |
|
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: nodejs#5039 PR-URL: nodejs#6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
On Linux and OS X systems, `fs.watch()` resolves the watched path to an inode. This clarifies that `fs.watch()` watches the inode and not the path. If the inode of the path subsequently changes, `fs.watch()` will continue watching the original inode and events for the path will no longer be emitted. This is expected behavior. Fixes: #5039 PR-URL: #6099 Reviewed-By: James M Snell <[email protected]>
1994: api_test: Fix bitcoind/parity log wait r=D4nte a=D4nte There are issues on Mac where it waits undefinitely for the right light for both nodes despite the line being present in the file. See nodejs/node#5039 for more info. Co-authored-by: Franck Royer <[email protected]>
I am on Mac OS X 10.11.1 with node.js 4.1.1. I also tried with node.js 5.x:
Steps:
master
other
branch, make some changes to the file and commit toother
branch=> I get a
rename
event for the first time I switch to theother
branch. After that, the events stop when switching branches.The text was updated successfully, but these errors were encountered: