HomeWildfire Games

Make real directory paths on the VFS predictable (retry)

Description

Make real directory paths on the VFS predictable (retry)

This is the same commit as rP25104, reverted in rP25105. Noted issues were fixed.

Partial revert/fix of rP13167 and rP13472.

Before this diff, it was possible for a mod containing a cache/ or a config/ folder to get written to incorrectly.
The issue is VFS can map multiple directories to one 'virtual' path, for reading mods. However, writing data is problematic: which path to choose?
The only viable solution is to use a path relative to the highest priority directory encountered in the VFS path, or write paths could be 'hijacked' by lower-priority mods.

This fixes these issues by:

  • Adding a new lookup mode ('Real-path') that explicitly picks the real path relative to the highest-priority subdirectory in the VFS Path.
  • Preventing overwriting a real directory with a lower priority one in general.
  • Revert rP8082's GetRealPath change, re-introducing the function as GetOriginalPath.

This also cleans up some duplication that led to empty mod folders in the user mod path, and cleans up loading the 'user' mod.
It also makes it explicit that a directory must be passed to Mount().

Note that the new 'realpath' lookup can still be somewhat complex with many mount points at various hierarchy levels, but it is at least predictable/deterministic without having to be careful about populating order.

Fixes #2553

Differential Revision: https://code.wildfiregames.com/D3728

Event Timeline

GameSetup.cpp
../../../source/ps/GameSetup/GameSetup.cpp: In function ‘void MountMods(const Paths&, const std::vector<CStr8>&)’:
../../../source/ps/GameSetup/GameSetup.cpp:414:14: warning: ‘priority’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  g_VFS->Mount(L"", modUserPath / "user" / "", userFlags, InDevelopmentCopy() ? 0 : priority + 1);
  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The commit broke --without-pch in test_vfs_real_path.h.