Skip to content

Commit

Permalink
Do not canonicalize the exe-candidate at all
Browse files Browse the repository at this point in the history
And here is why: #9991 (comment)
  • Loading branch information
Byron committed Oct 23, 2021
1 parent 4906ef2 commit cf8e464
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions crates/cargo-util/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,41 +123,13 @@ pub fn resolve_executable(exec: &Path) -> Result<PathBuf> {
});
for candidate in candidates {
if candidate.is_file() {
// PATH may have a component like "." in it, so we still need to
// canonicalize.
// Only do so if there are relative path components
let has_relative_path_components = candidate.components().any(|c| {
matches!(
c,
std::path::Component::ParentDir | std::path::Component::CurDir
)
});
return Ok(if has_relative_path_components {
// Assure symlinks to programs like 'echo' don't change the file-name after resolution.
// root program like 'coreutils' which relies on the executable name for proper function.
let file_name = candidate
.file_name()
.expect("executables have a file name")
.to_owned();
let candidate = candidate
.canonicalize()?
.parent()
.expect("a parent is always available for tools called in test-suite")
.join(file_name)
.to_owned();
if !candidate.is_file() {
continue;
}
candidate
} else {
candidate
});
return Ok(candidate);
}
}

anyhow::bail!("no executable for `{}` found in PATH", exec.display())
} else {
Ok(exec.canonicalize()?)
Ok(exec.into())
}
}

Expand Down

0 comments on commit cf8e464

Please sign in to comment.