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

Windows PathBuf/Path #81045

Closed
pderouen opened this issue Jan 15, 2021 · 2 comments
Closed

Windows PathBuf/Path #81045

pderouen opened this issue Jan 15, 2021 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@pderouen
Copy link

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

fn main() {
    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");
    if let Some(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.

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-pc-windows-gnu
release: 1.49.0
Backtrace

no back trace

@pderouen pderouen added the C-bug Category: This is a bug. label Jan 15, 2021
@ehuss
Copy link
Contributor

ehuss commented Jan 15, 2021

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.

@pderouen
Copy link
Author

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants