Skip to content

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

Merged
ivall merged 2 commits into
xcl-dev:mainfrom
raylitebull:fix/vfs-move-copy-and-whiteouts
Nov 23, 2026
Merged

ivall merged 2 commits into
xcl-dev:mainfrom
raylitebull:fix/vfs-move-copy-and-whiteouts

Conversation

@raylitebull

Copy link
Copy Markdown
Member

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 VFS hooks: the guard keeps the thread's last error #92): cargo build --workspace and cargo test --workspace -- --test-threads=4 pass (467 passed, 0 failed, 36 ignored, 0 new warnings).

@ivall
ivall merged commit 6ea7a64 into xcl-dev:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants