VFS: fix move/copy data loss, overwrite flags, and whited-out directory handling #95

Merged
raylitebull merged 2 commits from upstream-pr/96 into main 2026-11-23 11:25:27 +00:00
raylitebull commented 2026-11-23 11:10:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-23T11:10:34Z.


Summary

Fixes data-loss bugs on VFS move/copy/rename plus whited-out directory listing and type-check bugs in crates/xcl/src/{vfs.rs, vfs_hooks.rs} (split into 2 clean commits — data-loss fixes first, directory/whiteout fixes second):

Commit 1 (Data Loss): Case-only rename, overwrite flags, and failed copy/move whiteout resurrection

  1. Case-only & self-rename data loss (vfs_hooks.rs):
    • Previously, moving an un-overlaid game file to a different casing (G:\data\hello.txt -> G:\data\HELLO.TXT) copied it into the overlay and then called v.delete_file("data\\hello.txt"), deleting the newly created overlay file on case-insensitive NTFS and writing a whiteout — permanently destroying the file while returning TRUE.
    • move_file_vfs now detects same case-insensitive VFS relative paths: self-rename is a no-op, overlaid case-only rename renames in place, and un-overlaid case-only rename copies into the overlay with the new casing and commits without deleting or whiting out.
  2. Overwrite flags (MOVEFILE_REPLACE_EXISTING, bFailIfExists, COPY_FILE_FAIL_IF_EXISTS) (vfs_hooks.rs):
    • move_file_vfs now enforces MOVEFILE_REPLACE_EXISTING across the full VFS view (un-overlaid original, overlay, and external targets), returning ERROR_ALREADY_EXISTS when unset and ERROR_ACCESS_DENIED on directories.
    • CopyFileW, CopyFileExW, and CopyFile2 (reading dwCopyFlags after checking dwSize >= 8) enforce fail-if-exists against un-overlaid original files (ERROR_FILE_EXISTS / HRESULT_FROM_WIN32(ERROR_FILE_EXISTS)).
  3. Failed copy/move resurrecting deleted files (vfs.rs, vfs_hooks.rs):
    • Split Vfs::stage_write (creates overlay parent dirs without removing whiteouts) from Vfs::commit_write (removes whiteout only after the underlying copy/move succeeds) so a failing copy/move (e.g. missing source) never resurrects a whited-out original file.
    • hk_replace_file_w validates both replaced and replacement exist in the VFS (ERROR_FILE_NOT_FOUND) before mutating files.

Commit 2: Whited-out directory listing, type checks, and directory recreation

  1. Listing a whited-out directory (vfs_hooks.rs):
    • collect_game_entries checks !dir_rel.is_empty() && !v.is_dir(&dir_rel) and returns ERROR_PATH_NOT_FOUND instead of enumerating . and .. from the original directory.
  2. File/directory type checks (vfs.rs):
    • delete_file rejects original directories (ERROR_ACCESS_DENIED) and remove_dir rejects original files (ERROR_DIRECTORY) without writing whiteouts.
  3. Recreating a deleted directory (vfs.rs):
    • remove_whiteout pushes whiteouts down to immediate original children whenever a whited-out ancestor directory is un-hidden, so recreating a removed directory never resurrects original children.

Testing

  • Added 8 deterministic unit/hook tests covering every bug:
    • move_case_only_and_self_rename_preserve_file
    • move_enforces_replace_existing_and_overwrites_cleanly (including overwriting an existing file and reading it back intact)
    • copy_enforces_fail_if_exists_and_overwrites_cleanly (including overwriting an existing file and reading it back intact)
    • failed_copy_and_move_do_not_resurrect_whiteouts
    • replace_file_rejects_missing_or_whited_out_targets
    • delete_file_rejects_directories_and_remove_dir_rejects_files
    • recreating_removed_directory_does_not_resurrect_original_children
    • find_first_on_whited_out_and_recreated_directory
  • Verified after rebasing onto origin/main (60599a9, zero conflict with #92): cargo build --workspace and cargo test --workspace -- --test-threads=4 pass (467 passed, 0 failed, 36 ignored, 0 new warnings).
<!-- greyfinch-sync:ivall/xcl:issue:5451934053 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/96). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-23T11:10:34Z. --- ## Summary Fixes data-loss bugs on VFS move/copy/rename plus whited-out directory listing and type-check bugs in `crates/xcl/src/{vfs.rs, vfs_hooks.rs}` (split into 2 clean commits — data-loss fixes first, directory/whiteout fixes second): ### Commit 1 (Data Loss): Case-only rename, overwrite flags, and failed copy/move whiteout resurrection 1. **Case-only & self-rename data loss (`vfs_hooks.rs`):** - Previously, moving an un-overlaid game file to a different casing (`G:\data\hello.txt` -> `G:\data\HELLO.TXT`) copied it into the overlay and then called `v.delete_file("data\\hello.txt")`, deleting the newly created overlay file on case-insensitive NTFS and writing a whiteout — permanently destroying the file while returning `TRUE`. - `move_file_vfs` now detects same case-insensitive VFS relative paths: self-rename is a no-op, overlaid case-only rename renames in place, and un-overlaid case-only rename copies into the overlay with the new casing and commits without deleting or whiting out. 2. **Overwrite flags (`MOVEFILE_REPLACE_EXISTING`, `bFailIfExists`, `COPY_FILE_FAIL_IF_EXISTS`) (`vfs_hooks.rs`):** - `move_file_vfs` now enforces `MOVEFILE_REPLACE_EXISTING` across the full VFS view (un-overlaid original, overlay, and external targets), returning `ERROR_ALREADY_EXISTS` when unset and `ERROR_ACCESS_DENIED` on directories. - `CopyFileW`, `CopyFileExW`, and `CopyFile2` (reading `dwCopyFlags` after checking `dwSize >= 8`) enforce fail-if-exists against un-overlaid original files (`ERROR_FILE_EXISTS` / `HRESULT_FROM_WIN32(ERROR_FILE_EXISTS)`). 3. **Failed copy/move resurrecting deleted files (`vfs.rs`, `vfs_hooks.rs`):** - Split `Vfs::stage_write` (creates overlay parent dirs without removing whiteouts) from `Vfs::commit_write` (removes whiteout only after the underlying copy/move succeeds) so a failing copy/move (e.g. missing source) never resurrects a whited-out original file. - `hk_replace_file_w` validates both `replaced` and `replacement` exist in the VFS (`ERROR_FILE_NOT_FOUND`) before mutating files. ### Commit 2: Whited-out directory listing, type checks, and directory recreation 1. **Listing a whited-out directory (`vfs_hooks.rs`):** - `collect_game_entries` checks `!dir_rel.is_empty() && !v.is_dir(&dir_rel)` and returns `ERROR_PATH_NOT_FOUND` instead of enumerating `.` and `..` from the original directory. 2. **File/directory type checks (`vfs.rs`):** - `delete_file` rejects original directories (`ERROR_ACCESS_DENIED`) and `remove_dir` rejects original files (`ERROR_DIRECTORY`) without writing whiteouts. 3. **Recreating a deleted directory (`vfs.rs`):** - `remove_whiteout` pushes whiteouts down to immediate original children whenever a whited-out ancestor directory is un-hidden, so recreating a removed directory never resurrects original children. ## Testing - Added 8 deterministic unit/hook tests covering every bug: - `move_case_only_and_self_rename_preserve_file` - `move_enforces_replace_existing_and_overwrites_cleanly` (including overwriting an existing file and reading it back intact) - `copy_enforces_fail_if_exists_and_overwrites_cleanly` (including overwriting an existing file and reading it back intact) - `failed_copy_and_move_do_not_resurrect_whiteouts` - `replace_file_rejects_missing_or_whited_out_targets` - `delete_file_rejects_directories_and_remove_dir_rejects_files` - `recreating_removed_directory_does_not_resurrect_original_children` - `find_first_on_whited_out_and_recreated_directory` - Verified after rebasing onto `origin/main` (`60599a9`, zero conflict with #92): `cargo build --workspace` and `cargo test --workspace -- --test-threads=4` pass (467 passed, 0 failed, 36 ignored, 0 new warnings).
upstream-sync closed this pull request 2026-11-24 06:57:08 +00:00
ivall commented 2026-11-24 07:00:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T11:25:41Z.


Merged together with #95–#102 and checked on Windows 11 with an RX 9070: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7099630291 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/96#issuecomment-7099630291). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T11:25:41Z. --- Merged together with #95–#102 and checked on Windows 11 with an RX 9070: `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with `XCL_SPLIT_WAVE64=1`; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!95
No description provided.