Skip to content

Commit

Permalink
Fix handling of stale links to bpf-tools in cargo-build-bpf (#17772) (#…
Browse files Browse the repository at this point in the history
…19667)

(cherry picked from commit 910ac94)

Co-authored-by: Dmitri Makarov <[email protected]>
  • Loading branch information
mergify[bot] and dmakarov authored Sep 6, 2021
1 parent ad66189 commit a2b4359
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions sdk/cargo-build-bpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,17 @@ fn install_if_missing(
}
let source_path = source_base.join(package);
// Check whether the correct symbolic link exists.
let missing_source = if source_path.exists() {
let invalid_link = if let Ok(link_target) = source_path.read_link() {
link_target != target_path
} else {
true
};
if invalid_link {
let invalid_link = if let Ok(link_target) = source_path.read_link() {
if link_target != target_path {
fs::remove_file(&source_path).map_err(|err| err.to_string())?;
true
} else {
false
}
invalid_link
} else {
true
};
if missing_source {
if invalid_link {
#[cfg(unix)]
std::os::unix::fs::symlink(target_path, source_path).map_err(|err| err.to_string())?;
#[cfg(windows)]
Expand Down

0 comments on commit a2b4359

Please sign in to comment.