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

Path from events must be absolute #13

Open
msangel opened this issue Dec 17, 2019 · 2 comments
Open

Path from events must be absolute #13

msangel opened this issue Dec 17, 2019 · 2 comments

Comments

@msangel
Copy link

msangel commented Dec 17, 2019

As in usage place we might have no context information about the parent, and relative path not enough.

@msangel
Copy link
Author

msangel commented Dec 17, 2019

This is how this problem is fixed in one of forks: mingcheng@80c64f1

@msangel
Copy link
Author

msangel commented Dec 17, 2019

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;
    }
}

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