You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Path derived from a canonicalized PathBuf and then joined to another Path that includes ".\" in the path cannot be resolved correctly (Windows os error). Removing the leading ".\" or starting from a PathBuf that hasn't been canonicalized will allow the path to resolve correct (Windows finds the file).
I tried this code:
use std::path::{Path,PathBuf};fnmain(){let p0 = PathBuf::from(".\\empty_file.txt");let p0_canon = p0.canonicalize().unwrap();// using this instead will work// let p0_canon = PathBuf::from("c:\\full\\path\\to\\the\\file");ifletSome(p1) = p0_canon.parent(){let append = Path::new(".\\target\\debug\\testfile");println!("{:#?}",p1);println!("{:#?}",append);let p2 = p1.join(append);println!("{:#?}",p2);let canonicalize = p2.canonicalize();println!("{:#?}",canonicalize);}}
I expected to see this happen: I expect the final prinln to show Ok()
Instead, this happened: I get Err. The system cannot find the path specified.
This is a fairly well known problem where canonicalize returns a \\?\ device path which does not support relative paths or normalization. See #59117 and #42869 and all the linked issues.
A Path derived from a canonicalized PathBuf and then joined to another Path that includes ".\" in the path cannot be resolved correctly (Windows os error). Removing the leading ".\" or starting from a PathBuf that hasn't been canonicalized will allow the path to resolve correct (Windows finds the file).
I tried this code:
I expected to see this happen: I expect the final prinln to show Ok()
Instead, this happened: I get Err. The system cannot find the path specified.
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: