Skip to content

Commit

Permalink
fix(artifact): delete old final artifacts before rebuild
Browse files Browse the repository at this point in the history
Some linkers do not remove the executable, but truncate and modify it.
That results in the old hard-link being modified even after renamed.
We delete the old artifact here to prevent this behavior from confusing users.
See #8348.
  • Loading branch information
weihanglo committed Sep 21, 2022
1 parent bf1523b commit b47cacb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
paths::remove_file(&dst)?;
}
}

// Some linkers do not remove the executable, but truncate and modify it.
// That results in the old hard-link being modified even after renamed.
// We delete the old artifact here to prevent this behavior from confusing users.
// See rust-lang/cargo#8348.
if output.hardlink.is_some() && output.path.exists() {
_ = paths::remove_file(&output.path).map_err(|e| {
log::debug!(
"failed to delete previous output file `{:?}`: {e:?}",
output.path
);
});
}
}

fn verbose_if_simple_exit_code(err: Error) -> Error {
Expand Down

0 comments on commit b47cacb

Please sign in to comment.