Comments (9)
I think you could make a case for either behavior. The "move" isn't really doing anything to the file inside, so I suspect that's why it doesn't treat that as a "create" event for the file. Note that on Windows we actually use the native JDK implementation to watch recursively, so this is actually just what the native implementation does and not a specific behavior I decided on myself.
Did you check what this does on Linux? If it's consistent with Windows I'd be more inclined to look at changing the Mac behavior. But either way it'd be nice if the behavior was consistent between OSes.
from directory-watcher.
Thank you for your prompt response.
I guess Windows emits ENTRY_CREATE event for New Text Document.txt
before New folder
is registered in the watch service, and hence the watch service cannot notify the event.
DEBUG io.methvin.watcher.DirectoryWatcher - ENTRY_CREATE [C:\Users\jun_w\Goobox\New folder]
DEBUG io.methvin.watcher.DirectoryWatcher - ENTRY_MODIFY [C:\Users\jun_w\Goobox\New folder\popular_book_review.json]
DEBUG io.methvin.watcher.DirectoryWatcher - ENTRY_MODIFY [C:\Users\jun_w\Goobox\New folder]
When New folder
had a bigger file (popular_book_review.json
is about 150MB), ENTRY_MODIFY event for the file was notified. I think ENTRY_CREATE was emitted, then New folder
was registered, and ENTRY_MODIFY was emitted, so only ENTRY_MODIFY was notified.
However, it's impossible to register New folder
in advance and I agree current behavior may be intended by the JDK implementation.
Unfortunately, since our software doesn't support Linux yet, I haven't checked this issue in Linux.
from directory-watcher.
I'm curious which filesystem actions are causing those log entries. Is that from copying "New folder" from somewhere else?
from directory-watcher.
Yes, it is. I moved "New folder" which has a large file "popular_book_review.json" from outside of the watching folder but in the same drive.
from directory-watcher.
It's a bit disappointing if Windows has a race condition like you described. I haven't looked at their actual implementation but I thought the whole point of the FILE_TREE
modifier was to tell Windows you wanted all events for the entire tree.
The only way we could work around this is to traverse the entire file tree of a new directory when it's created. I'm open to potentially doing that but it could be a costly operation in some cases.
In most of my use cases of this library the race condition is not really an issue, since the application would be traversing the directory anyway to do whatever it needed to do (e.g. compiling code that changed).
from directory-watcher.
I'm trying to traverse the directory when ENTRY_CREATE is emitted with a directory, and it works so far.
If this library traverses the directory instead of the user, it'd be helpful. If I'm not mistaken, registerAll
traverses the directory. So if ENTRY_CREATE event for descendants can be emitted in that traverse, it seems not so costly. What do you think?
But, in my case, such double traversing the directory is not costly so far even I copied thousands files. I think it might be enough to mention about missing events in the doc.
from directory-watcher.
registerAll
shouldn't actually traverse the whole tree on Windows though, since Windows supports the ExtendedWatchEventModifier.FILE_TREE
modifier. DirectoryWatcher should detect that and only register the root.
Anyway, I do think it makes sense to emit extra events for descendants on ENTRY_CREATE
as long as we can do so consistently across platforms. A PR doing this would be welcome.
from directory-watcher.
It seems ironical because if the file tree is supported, walk directories to notify create events, and if the file tree isn’t supported, walk directories to register subdirectories….
from directory-watcher.
We probably also want to walk the directories to create events when FILE_TREE
is not supported. In that case we know we could have missed events between the time the parent directory was created and the time we start listening. In either case we should be able to check if we've already hashed the file to avoid creating multiple events.
from directory-watcher.
Related Issues (20)
- [JAVA] 0.9.3 Copy & Remove of folder structure does not produce CREATE events HOT 1
- Missing tag `0.9.6` upstream HOT 1
- New Release HOT 4
- Absolute path prevents events on macOS HOT 3
- Question on Using 2 Classes HOT 1
- LibCarbon failure on MacOS Big Sur HOT 12
- Allow watching directory non-recursively HOT 1
- Unable to detect file deletion events HOT 27
- File creation on Windows is sometimes not detected for copied files HOT 3
- Ensure consistent behavior when a root watched directory is deleted
- Define a minimal public API
- Watcher does not detect (re)moving a parent directory HOT 2
- DirectoryWatcher.watch() throws ClosedWatchServiceException when Watcher is closed HOT 4
- Access denied stops walking file tree HOT 7
- Does it work with mounted volumes with Docker? HOT 4
- Missing events when file is created too soon after watcher is initialized HOT 3
- Modification events are lost depending on editor - how the file is written - neovim HOT 7
- Duplicate events when editing file on Samba share HOT 7
- Fails with NoClassDefFoundError inside Wildfly HOT 2
- Suggestion: Fail (or handle!) watched path being a file instead of a directory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from directory-watcher.