Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions crates/xcl/src/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@ impl Vfs {
Decision::Use(p)
}
Target::Game { rel } => {
// a plain read: only `read_path_rel` asks the file system (titles open their files
// for reading thousands of times; each probe below costs about as much as the open)
if !Self::is_write(access, disposition, flags) && disposition != OPEN_ALWAYS {
return match self.read_path_rel(&rel) {
Some(p) => Decision::Use(p),
None => Decision::Fail(ERROR_FILE_NOT_FOUND),
};
}
let in_ov = self.visible_in_overlay(&rel);
let in_orig = self.visible_in_original(&rel);
let visible = in_ov || in_orig;
Expand Down Expand Up @@ -844,6 +852,29 @@ mod tests {
assert_eq!(v.redirected_writes(), vec!["data\\hello.txt".to_string(), "data\\new.bin".to_string()]);
}

#[test]
fn reads_take_the_original_and_read_only_open_always_still_creates() {
let f = Fixture::new("rdonly");
let v = &f.vfs;
let data = f.game().join("data");
// a plain read of a missing file names the original: the open itself reports the error
assert_eq!(
v.open_decision("G:\\data\\missing.bin", 0x8000_0000, OPEN_EXISTING, 0),
Decision::Use(data.join("missing.bin").to_string_lossy().to_string())
);
// OPEN_ALWAYS reads an existing file where it is …
assert_eq!(
v.open_decision("G:\\data\\hello.txt", 0x8000_0000, OPEN_ALWAYS, 0),
Decision::Use(data.join("hello.txt").to_string_lossy().to_string())
);
// … and creates a missing one in the overlay even without write access
let d = v.open_decision("G:\\data\\created.bin", 0x8000_0000, OPEN_ALWAYS, 0);
let Decision::Use(p) = d else { panic!("{d:?}") };
assert!(p.contains("overlay"), "{p}");
assert!(!data.join("created.bin").exists());
assert_eq!(v.redirected_writes(), vec!["data\\created.bin".to_string()]);
}

#[test]
fn delete_is_a_persistent_whiteout() {
let f = Fixture::new("wo");
Expand Down
Loading