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

Strange paths in events on windows #95

Closed
dyule opened this issue Aug 31, 2016 · 3 comments
Closed

Strange paths in events on windows #95

dyule opened this issue Aug 31, 2016 · 3 comments

Comments

@dyule
Copy link

dyule commented Aug 31, 2016

I'm presently relying on the version of rsnotify direct from github, since the version on crates.io doesn't seem to have any way of tracking renames, or if it does, it isn't documented.

However, when watching a directory (in my case C:\Users\Daniel\dir1), the create notification (and maybe others too, but it crashes before I can check them) has a path with a whole bunch of leading slashes: \\?\C:\Users\Daniel\dir1\New Text Document.txt I imagine this has something to do with partitions or volumes or some such, but it makes it pretty tricky to access the file.

@dyule
Copy link
Author

dyule commented Aug 31, 2016

I should also mention that trying to strip out those leading characters from the path doesn't work; the path doesn't seem to think they are in there, despite the fact that when printed, it definitely is. It also won't allow me strip its actual prefix (C:\Users\Daniel\dir1). This was all working before I switched to the github version from the crates version.

@dfaust
Copy link
Collaborator

dfaust commented Aug 31, 2016

Good catch.
I'm developing on linux and due to stupid nvidia (long story) my VM with windows doesn't work right now, so I can't test it at the moment.
But I think this is a side effect of fixing #90. The watch path gets canonicalized internally. I guess it would make sense to only do that when necessary (and then de-canonicalize before sending the path to the user).
Could you provide some code how you tried to strip the prefix?

@dyule
Copy link
Author

dyule commented Aug 31, 2016

Thanks for the quick response. I was trying to strip the prefix like this:

let actual_path = event.path.unwrap();
let better_path = actual_path.strip_prefix(Path::new("\\\\?\\")).unwrap();

Since posting, I've managed to circumvent the issue by converting actual_path to a string, stripping the characters off and then converting it back to a path:

let path_string = actual_path.to_str().unwrap().to_string();
let better_path = Path::new(path_string.trim_left_matches("\\\\?\\")).to_path_buf();

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

2 participants