rxfilewatcher
rxfilewatcher copied to clipboard
Path from events must be absolute
As in usage place we might have no context information about the parent, and relative path not enough.
This is how this problem is fixed in one of forks: https://github.com/mingcheng/rx-filewatcher.java/commit/80c64f1e7f65c5f5c75309ee926d218954aa3112
But that code has a problem: not every event is Path event. Here's my function based on that but with this extra check:
private WatchEvent<?> withAbsolutePath(WatchEvent<?> event, Path fileAbsolutePath) {
Class<?> type = event.kind().type();
if (type.isAssignableFrom(Path.class)) {
return new WatchEvent<Path>() {
@Override
public Kind kind() {
return event.kind();
}
@Override
public int count() {
return event.count();
}
@Override
public Path context() {
return fileAbsolutePath;
}
};
} else {
return event;
}
}