feat: Implement fallback file move
This commit is contained in:
parent
3215670ae0
commit
b376e6429b
1 changed files with 16 additions and 11 deletions
11
src/main.rs
11
src/main.rs
|
@ -42,18 +42,23 @@ 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) {
|
||||||
|
// 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
|
let tmp_path = tmp_path
|
||||||
.keep()
|
.keep()
|
||||||
.with_context(|| "failed to persist temporary file")?;
|
.with_context(|| "failed to persist temporary file")?;
|
||||||
bail!(
|
bail!(
|
||||||
"failed to rename temporary file to override the sound bank: {}!\n\
|
"failed to rename or move temporary file to override the sound bank: {}!\n\
|
||||||
Please manually copy the file from {} to {}.",
|
Please manually move the file from {} to {}.",
|
||||||
err,
|
err,
|
||||||
tmp_path.display(),
|
tmp_path.display(),
|
||||||
path.as_ref().display()
|
path.as_ref().display()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue