Skip to content

Commit

Permalink
fix(symsorter): Don't create files twice (#1575)
Browse files Browse the repository at this point in the history
If, for some reason, there are two different debug files
with the same ID, we previously would open the target file
twice and write to it in parallel, which could cause data
corruption (only observed when using compression, which
might be a matter of speed). Now instead we only create
the file if it doesn't exist and print a warning otherwise.
The resulting warnings look like

> WARNING: File out-dir/bc/0f534e9ab5a4c7/debuginfo already exists, you seem to have duplicate debug files for ID bc0f534e9ab5a4c7.
> Skipping foobar.debug.
  • Loading branch information
loewenheim authored Jan 7, 2025
1 parent fd46879 commit 717bb0b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/symsorter/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,21 @@ fn process_file(
style(obj.arch()).yellow(),
style(new_filename.display()).cyan(),
);
let mut out = fs::File::create(&new_filename)?;

let mut out = match fs::File::create_new(&new_filename) {
Ok(out) => out,
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
eprintln!(
"{}: File {} already exists, you seem to have duplicate debug files for ID {}.\n\
Skipping {filename}.",
style("WARNING").red().bold(),
new_filename.display(),
get_unified_id(&obj).unwrap(),
);
return Ok(vec![]);
}
Err(e) => return Err(e.into()),
};

if compression_level > 0 {
copy_encode(obj.data(), &mut out, compression_level)?;
Expand Down

0 comments on commit 717bb0b

Please sign in to comment.