Skip to content

Commit 4906ef2

Browse files
committed
Assure the binary name won't change after canonicalization, and keep looking if it does.
1 parent 0d06193 commit 4906ef2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

crates/cargo-util/src/paths.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,30 @@ pub fn resolve_executable(exec: &Path) -> Result<PathBuf> {
125125
if candidate.is_file() {
126126
// PATH may have a component like "." in it, so we still need to
127127
// canonicalize.
128-
// Only do so if there are relative path components, otherwise symlinks to 'echo' may be resolved to their
129-
// root program like 'coreutils' which relies on the executable name for proper function.
128+
// Only do so if there are relative path components
130129
let has_relative_path_components = candidate.components().any(|c| {
131130
matches!(
132131
c,
133132
std::path::Component::ParentDir | std::path::Component::CurDir
134133
)
135134
});
136135
return Ok(if has_relative_path_components {
137-
candidate.canonicalize()?
136+
// Assure symlinks to programs like 'echo' don't change the file-name after resolution.
137+
// root program like 'coreutils' which relies on the executable name for proper function.
138+
let file_name = candidate
139+
.file_name()
140+
.expect("executables have a file name")
141+
.to_owned();
142+
let candidate = candidate
143+
.canonicalize()?
144+
.parent()
145+
.expect("a parent is always available for tools called in test-suite")
146+
.join(file_name)
147+
.to_owned();
148+
if !candidate.is_file() {
149+
continue;
150+
}
151+
candidate
138152
} else {
139153
candidate
140154
});

0 commit comments

Comments
 (0)