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

workaround unc path on windows #38

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

ncloudioj
Copy link
Member

@ncloudioj ncloudioj commented Jun 13, 2018

Workaround the UNC path on Windows, all the tests passed in the current stable toolchain "stable-x86_64-pc-windows-msvc"

Note that:

  • It can't handle the paths longer than MAX_PATH
  • It can't handle the paths with the non-utf8 characters

@mykmelez

@ncloudioj ncloudioj force-pushed the fix-windows-unc-path branch from 16326c0 to c79cde7 Compare June 13, 2018 21:06
src/manager.rs Outdated
fn canonicalize_path<'p, P>(path: P) -> io::Result<PathBuf>
where P: Into<&'p Path> {
let canonical = path.into().canonicalize()?;
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should preface this block to compile it only on Windows:

    #[cfg(windows)]

Then other platforms won't pay the cost of the workaround.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will tweak it a bit based on all other review feedback.

@@ -44,6 +46,24 @@ lazy_static! {
};
}

// Workaround the UNC path on Windows, see https://github.com/rust-lang/rust/issues/42869.
// Otherwise, `Env::from_env()` will panic with error_no(123).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to file this upstream, in lmdb-rs, or perhaps farther upstream, in LMDB itself, although the latter requires grokking the OpenLDAP Issue Tracking System, so I'd probably start with the former. 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to do them both, i.e. having a workaround in rkv for the time being so that it works on Windows at least to get CI rolling. On the other hand, pop this back to upstream(s) in hope that this would get fixed in the right place. Yep, let me try it from lmdb-rs first, cuz I suspect that the windows mmap syscall won't play nice with UNC path, since it returned a error_no(123), which means it received an invalid directory according to its document.

Heh, I used to be on the lmdb's mailing list a while ago, and filed various bugs there, will try to grok their new issue tracking system if necessary :)

src/manager.rs Outdated
let mut canonical_path = canonical.to_str().unwrap();
if canonical_path.starts_with(r"\\?\") {
canonical_path = &canonical_path[r"\\?\".len()..];
return Ok(PathBuf::from(canonical_path));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wonder if it would be more robust to unconditionally strip the UNC prefix from paths via the Url crate, i.e. something like:

Url::from_file_path(canonical).expect("URL").to_file_path().expect("path")

I don't know if this would cover more cases or fail less often than the current implementation, however. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will check it out.

@@ -44,6 +46,24 @@ lazy_static! {
};
}

// Workaround the UNC path on Windows, see https://github.com/rust-lang/rust/issues/42869.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, rust-lang/rust#42869, I know it well (unfortunately).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, so you've also been there before. Such a small world! :)

@ncloudioj ncloudioj force-pushed the fix-windows-unc-path branch from c79cde7 to e469367 Compare June 14, 2018 18:56
@ncloudioj
Copy link
Member Author

Refactored it by using the url crate.

Also, filed an issue for this in lmdb-rs.

Copy link
Contributor

@mykmelez mykmelez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@mykmelez mykmelez merged commit 245275a into mozilla:master Jun 14, 2018
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

Successfully merging this pull request may close these issues.

2 participants