From 8bb1358575db894e54fababc9615f27f6ca2d7eb Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Sat, 19 Nov 2016 15:12:41 +0000 Subject: [PATCH] Canonicalize the path and then strip off the `\\?\` prefix before creating the reparse point. --- src/rustup-utils/src/raw.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rustup-utils/src/raw.rs b/src/rustup-utils/src/raw.rs index 2bce4fe2ab..a9d3a721af 100644 --- a/src/rustup-utils/src/raw.rs +++ b/src/rustup-utils/src/raw.rs @@ -207,6 +207,11 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { inner(s.as_ref()) } + // We're using low-level APIs to create the junction, and these are more picky about paths. + // For example, forward slashes cannot be used as a path separator, so we should try to + // canonicalize the path first. + let target = try!(fs::canonicalize(target)); + try!(fs::create_dir(junction)); let path = try!(to_u16s(junction)); @@ -228,7 +233,7 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { // FIXME: this conversion is very hacky let v = br"\??\"; let v = v.iter().map(|x| *x as u16); - for c in v.chain(target.as_os_str().encode_wide()) { + for c in v.chain(target.as_os_str().encode_wide().skip(4)) { *buf.offset(i) = c; i += 1; }