Skip to content

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

@brainbytes42

Description

@brainbytes42

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions