1
Fork 0

feat: Implement fallback file move

This commit is contained in:
Lucas Schwiderski 2022-04-26 20:47:53 +02:00
parent 3215670ae0
commit b376e6429b
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -42,17 +42,22 @@ where
tmp.into_temp_path() tmp.into_temp_path()
}; };
if let Err(err) = fs::rename(&tmp_path, &path) { if let Err(_) = fs::rename(&tmp_path, &path) {
let tmp_path = tmp_path // Attempt manual copy-and-delete
.keep() let mut tmp = File::open(&tmp_path).with_context(|| "failed to open tempfile for reading")?;
.with_context(|| "failed to persist temporary file")?; let mut f = File::open(&path).with_context(|| "failed to open destination file")?;
bail!( if let Err(err) = io::copy(&mut tmp, &mut f) {
"failed to rename temporary file to override the sound bank: {}!\n\ let tmp_path = tmp_path
Please manually copy the file from {} to {}.", .keep()
err, .with_context(|| "failed to persist temporary file")?;
tmp_path.display(), bail!(
path.as_ref().display() "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(()) Ok(())