diff --git a/src/main.rs b/src/main.rs index e7e353b..1b4c4cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,17 +42,22 @@ where tmp.into_temp_path() }; - if let Err(err) = fs::rename(&tmp_path, &path) { - let tmp_path = tmp_path - .keep() - .with_context(|| "failed to persist temporary file")?; - bail!( - "failed to rename temporary file to override the sound bank: {}!\n\ - Please manually copy the file from {} to {}.", - err, - tmp_path.display(), - path.as_ref().display() - ); + if let Err(_) = fs::rename(&tmp_path, &path) { + // Attempt manual copy-and-delete + let mut tmp = File::open(&tmp_path).with_context(|| "failed to open tempfile for reading")?; + let mut f = File::open(&path).with_context(|| "failed to open destination file")?; + if let Err(err) = io::copy(&mut tmp, &mut f) { + let tmp_path = tmp_path + .keep() + .with_context(|| "failed to persist temporary file")?; + bail!( + "failed to rename or move temporary file to override the sound bank: {}!\n\ + Please manually move the file from {} to {}.", + err, + tmp_path.display(), + path.as_ref().display() + ); + } } Ok(())