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,18 +42,23 @@ where
tmp.into_temp_path()
};
if let Err(err) = fs::rename(&tmp_path, &path) {
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 temporary file to override the sound bank: {}!\n\
Please manually copy the file from {} to {}.",
"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(())
}