Skip to content

fix: stop map cache from deleting maps on launch - #184

Open
AhPlace2 wants to merge 1 commit into
Rhythia:indevfrom
AhPlace2:fix/map-cache-path-deletion
Open

AhPlace2 wants to merge 1 commit into
Rhythia:indevfrom
AhPlace2:fix/map-cache-path-deletion

Conversation

@AhPlace2

Copy link
Copy Markdown

Part of #133 (item 1: map cache deletes maps on launch).

Problem

  • syncFiles deleted the map's files from disk whenever re-parsing a cached map threw. A parse failure isn't proof the map is broken, so this could wipe user maps on launch.
  • Cached FolderPaths could contain mixed separators (MapParser.Encode used Path.Combine, giving .../maps\Name on Windows). On a real cache I checked, 32 of 151 entries had this. addNonCachedFiles compared raw DB paths against normalized disk paths, so those maps never matched.
  • For imported .phxm files, addNonCachedFiles stored the .phxm path as FolderPath instead of the extracted folder. The .phxm is deleted after extraction, so the entry was dropped and rebuilt every launch.

Changes

  • syncFiles: on parse failure, log and remove the entry from the cache only; files on disk are left untouched.
  • syncFiles: normalize existing FolderPaths to forward slashes and save them.
  • addNonCachedFiles: compare normalized paths; keep the folder path returned by the parser.
  • InsertMap: normalize both paths before the compare that guards Directory.Delete.
  • MapParser.Encode / MapParser.PHXM: store and look up FolderPath with forward slashes.

Item 2 of #133 (x.Hash == x.Hash) no longer exists after the cache rework. Item 3 (.txt import nulls) is left for a separate PR.

Testing

Windows, Godot 4.7.2 .NET, on a backed-up user folder with 151 maps:

  • Corrupted one map's metadata.json and touched objects.phxmo so a re-parse is forced. The map was removed from the cache with a log message and its folder stayed on disk (previously the folder was deleted).
  • After a normal launch, 0 of 151 cache entries contain backslashes (was 32), all 151 maps remain, and no cached maps are re-decoded on launch.
  • dotnet csharpier check . and dotnet format --verify-no-changes Rhythia.csproj pass.

AI usage

This PR was written with help from Claude (Claude Code): it helped investigate the cache code, write the changes and draft this description. I reviewed and tested the changes myself and can explain and fix them.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant