feat: Implement fallback file move
This commit is contained in:
parent
3215670ae0
commit
b376e6429b
1 changed files with 16 additions and 11 deletions
27
src/main.rs
27
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(())
|
||||
|
|
Loading…
Add table
Reference in a new issue