Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fs.watch on Windows: Watching a directory blocks external rename #8371

Closed
jorangreef opened this issue Sep 15, 2014 · 5 comments
Closed

fs.watch on Windows: Watching a directory blocks external rename #8371

jorangreef opened this issue Sep 15, 2014 · 5 comments
Labels

Comments

@jorangreef
Copy link

Using fs.watch to watch a directory on Windows currently blocks that directory from being deleted or renamed by the user.

adobe/brackets#6551 has more discussion on the issue:

Using "FILE_SHARE_DELETE in the CreateFile() call will keep the code from locking the folder that you're wanting to watch with ReadDirectoryChangesW(). However, even if you use that flag, the parent folder of the watched folder will be locked by the ReadDirectoryChangesW() call."

This is not so much a problem (and is probably to be expected on Windows), except that fs.watch is also not recursive on Windows, so watching an entire tree requires recursive watches on all subdirectories. But then these cannot be renamed or deleted by the user either and this is a problem.

Also that same discussion refers to a recursive flag for ReadDirectoryChangesW?

@bnoordhuis
Copy link
Member

I think this is partially a dup of #3963?

By the way, the recursive flag you mention is always FALSE with node.js / libuv. Not sure why but I imagine it could be for feature parity with other platforms (fs.watch tries to capture greatest common denominator behavior) or because recursively watching C:\ is a good way to lock up the system.

@jorangreef
Copy link
Author

I tried with Node 11.13 on Windows, and it looks like the watched directory itself is no longer locked but it's parent directory is. This is partially a dup of #3963 but it's better that it just locks the parent directory and not the watched directory.

I saw in adobe/brackets#6551 that it looks like they managed to write their own binding of ReadDirectoryChangesW that relied on Windows to watch recursively without locking the system.

fs.watch on mac is working great now as you can watch a directory and its entire subtree simply by passing the "recursive: true" option.

I don't mind writing a separate recursive watcher using fs.watch for inotify on linux. This would be as per http://lwn.net/Articles/604686/ and I have most of it working well.

The problem with fs.watch now on Windows, is that fs.watch is not using ReadDirectoryChangesW to monitor the entire subtree using a recursive option, and I can't do that manually myself with multiple watches on subdirectories as this would lock up those subdirectories for the user on Windows.

At best, all I can do I think is to monitor the root and immediate child directories. This would then only lock the root directory on Node 11.13 (there's a new shared flag passed to ReadDirectoryChangesW which does not lock the watched directory itself).

@bpasero
Copy link

bpasero commented Feb 6, 2015

Can this be given a second thought: Please expose the recursive option for windows at least. The current way of installing another watcher on each subdirectory is so bad, that you should rather not expose it. For one, it locks folders, and for other, it consumes so much CPU and memory to walk down the directory structure that it is useless. The native option to recurse is so much more efficient.

@Elephant-Vessel
Copy link

Is this still an issue in the newer versions of node?

@jorangreef
Copy link
Author

It's not actually an issue in Node, but the way that Windows works. Newer versions of Node now support recursive watchers on Windows, so only the watched directory (and possibly the parent of that dircetory) is locked from being deleted on Windows.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants