-
Notifications
You must be signed in to change notification settings - Fork 34
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
Support for path contexts + misc improvements and fixes #58
Conversation
-Carbon returns real paths, this will not map added paths which are symbolic. To address this it turns the real path back into the user provided path. -Fixed some tests, by making them await longer Improvements -When underlying root paths were deleted, it would not detect and close the Carbon deamon thread or clean up the paths or invalidate the WatchKey. This is now addressed -Can now check if DirectoryWatcher is open or closed. -Added pom.xml so maven sort of works, but it's a quick hack and can be improved.- Feature -Allow a context value to be associated with a given subtree (i.e. from root path and all child paths), and provided as part of the Event. This avoids having to search for matching roots, to lookup a context value.
I should add I only checked that the added maven pom.xml and test work. I notice the SBT scala better stuff fails, it probably needs updating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request! I like the ideas but I had a few concerns.
@@ -0,0 +1,67 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a maven build?
I'm happy to discuss alternative build systems, but I think it makes more sense to discuss this in a separate issue before we make any changes. Ideally we should choose a single build system and stick with it for everything, and not try to build the project with multiple build systems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't, you can exclude it. It's just easier for me, as it was what I was familiar with, and works well in my IDE. I put it there, as it may make things easier for other people too, who don't have all the SBT/Scala stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I see your point. It just hard to make sure things are consistent between the maven and sbt builds, so it ultimately ends up creating more issues for us to fix.
I am eventually thinking about splitting out the better-files extension into a completely separate library (with separate release cycle) so maybe that's the right time to consider the maven stuff.
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
Btw I'm on gitter, if you want to chat. Left some messages for you there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more suggestions that might simplify things
core/src/main/java/io/methvin/watcher/DirectoryChangeEvent.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,67 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I see your point. It just hard to make sure things are consistent between the maven and sbt builds, so it ultimately ends up creating more issues for us to fix.
I am eventually thinking about splitting out the better-files extension into a completely separate library (with separate release cycle) so maybe that's the right time to consider the maven stuff.
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
All suggestions seem reasonable. Rather than reply individually, i'll rework them over next few days and we can re-review them. Btw one thing I don't think was necessary, was the thread I used to close the Carbon API thread. I only did it, as I wasn't sure if it would deadlock if it was done inplace. If you feel the code won't deadlock, I can do it without needing a thread. |
I don't think the extra thread is necessary based on my understanding of where the locking is happening. Was there a specific place you were concerned it would deadlock? |
OK, so I just removed that thread used to close the carbon API, hopefully it's ok. I wasn't sure how this was working, so was being cautious. |
It looks like there's now a test failing on linux and windows builds:
Any idea what might be causing that? |
@@ -145,6 +148,8 @@ public AbstractWatchKey register( | |||
flags); | |||
|
|||
final CFRunLoopThread thread = new CFRunLoopThread(streamRef, file.toFile()); | |||
callback.onClose(() -> {watchKey.watchService().close(thread, callback, file); return null;}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the return value, so you can change the type to Runnable
to avoid the ugly return null
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I've had limited time to look at this. I really appreciate the improvements but I also want to make sure we're confident in the changes, since several major projects rely on this library.
Looking at your tests, I see you have the line:
await().atMost(3, TimeUnit.SECONDS).until(() -> recorder.events.size() == 33);
So you're expecting 33 events from the three calls to createStructure2
. But it's not obvious to me why you're expecting that number of events.
You might also want to try with hashing, since some platforms fire duplicate events. The cross-platform guarantees of this library can be relaxed when it comes to duplicate events, as long as they make sense. For example, sometimes you'll get multiple modify events instead of one, as the file is being written out.
Also, my understanding is that registeredContexts
is an internal data structure to map each path registered in the WatchService
to the root path that was registered in DirectoryWatcher
. Actually if that's the case, maybe we should name it something more obvious like registeredPathToRootPath
. The term context
is actually a little confusing to me because there's something called context
on the WatchEvent
which only refers to the registered path in the WatchService
, which will be different on Linux, for example, or any other platform that doesn't support recursive watching on the WatchService
.
If you'd like, you could split off the macOS-only improvements to another PR so we can get those out sooner.
linux tests fix
-removed getRegisteredContexts -changed registeredContexts to registeredPathToRootPath
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
core/src/main/java/io/methvin/watchservice/MacOSXListeningWatchService.java
Outdated
Show resolved
Hide resolved
9cf59fc
to
99017cc
Compare
@mdproctor I made some changes that appear to fix the test failures. The main change is that I moved the tests that delete the root directory into an I also removed uses of Anyway, let me know if those changes look good. If so I'll merge and release. |
Bug
-Carbon returns real paths, this will not map added paths which are symbolic. To address this it turns the real path back into the user provided path.
-Fixed some tests, by making them await longer
Improvements
-When underlying root paths were deleted, it would not detect and close the Carbon deamon thread or clean up the paths or invalidate the WatchKey. This is now addressed
-Can now check if DirectoryWatcher is open or closed.
-Added pom.xml so maven sort of works, but it's a quick hack and can be improved.-
Feature
-Allow a context value to be associated with a given subtree (i.e. from root path and all child paths), and provided as part of the Event. This avoids having to search for matching roots, to lookup a context value.