Skip to content
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

Suggestion: Fail (or handle!) watched path being a file instead of a directory #95

Open
brainbytes42 opened this issue Jul 31, 2023 · 0 comments

Comments

@brainbytes42
Copy link

I just tried out your library, as i found the 'pure' java way using the WatchService kind of ugly - nice work to wrap that with this library!

When playing around, I forgot to get my dummy-file's parent directory when I added the path to your DirectoryWatcher's builder. As a result, I got no events when modifying the file.

The WatchService fails with java.nio.file.NotDirectoryException in this case - with your library everything seemed ok and I didn't get any sing of my mistake other than nothing happen...

So my suggestion would be to either fail for non-directory Paths as java does - or, even better, internally just watch the files parent directory and add a filter to get only events for the respective file. That would be really cool... ;-)

DirectoryWatcher.builder()
                .path(dummyPath.getParent())   // <- initially, I forgot getPatent() for my dummy-textfile
                .listener(event -> System.out.println("  \\-> EVENT = " + event))
                .build()
                .watchAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant