Skip to content

install::sanitize_sh(Path) breaks paths in Windows 10 #132507

Closed
@Houtamelo

Description

@Houtamelo

When running x install, I was getting the following error:

Installing stage2 docs (x86_64-pc-windows-msvc)
sh: /C/Users/anton/Documents/rust_compilers/unchained/build/tmp/tarball/rust-docs/x86_64-pc-windows-msvc/rust-docs-nightly-x86_64-pc-windows-msvc/install.sh: No such file or directory

I found that the source of the issue was inside the function sanitize_sh, located in: "src/bootstrap/src/core/build_steps/install.rs":

fn sanitize_sh(path: &Path) -> String {
    let path = path.to_str().unwrap().replace('\\', "/");
    return change_drive(unc_to_lfs(&path)).unwrap_or(path);

    fn unc_to_lfs(s: &str) -> &str {
        s.strip_prefix("//?/").unwrap_or(s)
    }

    fn change_drive(s: &str) -> Option<String> {
        let mut ch = s.chars();
        let drive = ch.next().unwrap_or('C');
        if ch.next() != Some(':') {
            return None;
        }
        if ch.next() != Some('/') {
            return None;
        }
        Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
    }
}

change_drive turns paths such as "C:/user/foo" into "/C/user/foo", which makes those paths invalid, resulting in "No such file or directory" errors.

In my fork, I commented the call to change_drive and returned path directly:

let path = path.to_str().unwrap().replace('\\', "/");
return path;

Which fixed the issue, x install then ran without any problems, everything was installed correctly.

Meta

OS: Windows 10 x64
rust-lang commit: ef972a3

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions