mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-25 13:57:45 +00:00
Fix issue where patches could panic because file didn't exist
Some of the recent boot updates now include patch files that try to
ask us to remove files that were already deleted. Now the patch process
is smarter and will quietly warn that said operation failed but will
continue to chug along.
(cherry picked from commit 8e6b0dd6b4
)
This commit is contained in:
parent
9618ab551a
commit
f2132e813f
1 changed files with 15 additions and 9 deletions
20
src/patch.rs
20
src/patch.rs
|
@ -10,7 +10,7 @@ use std::path::PathBuf;
|
||||||
use binrw::binread;
|
use binrw::binread;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
use tracing::debug;
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
use crate::common::Region;
|
use crate::common::Region;
|
||||||
use crate::sqpack::read_data_block_patch;
|
use crate::sqpack::read_data_block_patch;
|
||||||
|
@ -576,20 +576,26 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
file.seek(SeekFrom::Current(4))?;
|
file.seek(SeekFrom::Current(4))?;
|
||||||
|
|
||||||
// now apply the file!
|
// now apply the file!
|
||||||
let mut new_file = OpenOptions::new()
|
let new_file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(file_path)?;
|
.open(&file_path);
|
||||||
|
|
||||||
|
if let Ok(mut file) = new_file {
|
||||||
if fop.offset == 0 {
|
if fop.offset == 0 {
|
||||||
new_file.set_len(0)?;
|
file.set_len(0)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_file.seek(SeekFrom::Start(fop.offset))?;
|
file.seek(SeekFrom::Start(fop.offset))?;
|
||||||
new_file.write_all(&data)?;
|
file.write_all(&data)?;
|
||||||
|
} else {
|
||||||
|
warn!("{file_path} does not exist, skipping.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SqpkFileOperation::DeleteFile => {
|
SqpkFileOperation::DeleteFile => {
|
||||||
fs::remove_file(file_path.as_str())?;
|
if fs::remove_file(file_path.as_str()).is_err() {
|
||||||
|
warn!("Failed to remove {file_path}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SqpkFileOperation::RemoveAll => {
|
SqpkFileOperation::RemoveAll => {
|
||||||
let path: PathBuf =
|
let path: PathBuf =
|
||||||
|
|
Loading…
Add table
Reference in a new issue