Skip to content

The new Windows exe resolver has changed broken symlink behaviour #91177

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ChrisDenton opened this issue Nov 24, 2021 · 0 comments · Fixed by #91182
Closed

The new Windows exe resolver has changed broken symlink behaviour #91177

ChrisDenton opened this issue Nov 24, 2021 · 0 comments · Fixed by #91182
Assignees
Labels
O-windows Operating system: Windows

Comments

@ChrisDenton
Copy link
Member

ChrisDenton commented Nov 24, 2021

The old resolver would try to run broken symlinks. The new one skips them and continues searching.

To test this I created the simplest program that will run successfully.

Z:\test> mkdir exists
Z:\test> cd exists
Z:\test\exists> gc exe_exists.rs
fn main() {}
Z:\test\exists> rustc exe_exists.rs
Z:\test\exists> cd ..
Z:\test> 

Then I used the following test program:

// run_symlink.rs
use std::process::Command;
use std::os::windows::fs::symlink_file;
use std::env;
use std::fs;

fn main() -> std::io::Result<()> {
    // Get the directory of the working exe
    let mut exists = env::current_dir()?;
    exists.push("exists");

    // Set up a directory for the broken symlink...
    let mut bins = env::current_dir()?;
    bins.push("bins");
    fs::create_dir(&bins)?;

    // ...and create the symlink.
    let mut exe_path = bins.clone();
    exe_path.push("exe_exists.exe");
    symlink_file("DOES NOT EXIST", &exe_path)?;

    // Set up the `PATH` environment variable with our paths.
    let paths = env::join_paths(&[&bins, &exists]).unwrap();
    env::set_var("PATH", paths);

    // Try to run the file. It will try the broken symlink first.
    let result = Command::new("exe_exists.exe").spawn();
    println!("{:?}", result);

    // Cleanup
    fs::remove_dir_all(&bins)?;
    Ok(())
}

The result of compiling and running this program:

Z:\test> rustc +stable run_symlink.rs
Z:\test> ./run_symlink
Err(Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." })
Z:\test> rustc +nightly run_symlink.rs
Z:\test> ./run_symlink
Ok(Child { stdin: None, stdout: None, stderr: None, .. })

@rustbot claim
@rustbot label +O-windows

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants