Fix patch PCKs incorrectly marking imported resources for removal #102099
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #102098.
This fixes an issue when exporting patch PCKs, where imported assets would incorrectly end up being marked for removal.
The fundamental problem was that the code (introduced by me in #97356) that compared against the currently loaded
PackedData
inEditorExportPlatform::export_project_files
had an incomplete view of the files that had actually been saved to the newly written PCK, which resulted in them being interpreted as missing and thus written out as removals to the patch PCK. On top of that, this code didn't actually look at the "final" exported paths but instead relied on various intermediate lists, which was likely quite brittle to begin with.This pull request resolves this by adding a
EditorExportSaveProxy
class that's meant to be used (purely internally) for all file saves happening inEditorExportPlatform::export_project_files
, effectively "detouring" theEditorExportSaveFunction
function pointer that's passed intoEditorExportPlatform::export_project_files
. This class then tracks every file saved, in the appropriate "normalized" format of*.simplify_path().trim_prefix("res://")
, which is then referenced at the end when checking to see which files are missing and should be marked for removal in the patch PCK.This also happens to resolve a performance regression that was introduced (once again, by me) as part of #97356, when exporting patches, as we were doing a linear search of potentially thousands of loaded files across multiple lists, some of which could be in the thousands themselves. This was also made worse by the fact that we normalized every path (using the above mentioned format) as we compared against it.
Now with every written out path stored in
EditorExportSaveProxy::saved_paths
, in the format we'd expect it to be when loaded, we can omit any sort of normalization and just do a single quickHashSet
lookup for every loaded file, greatly alleviating this performance regression.I should probably also mention that this
EditorExportSaveProxy
could technically be replaced entirely by a reference-capturing lambda that wrapsp_save_func
, but given the aversion to lambdas I opted to go this route instead. I'd be curious to hear any other suggestions for a cleaner solution.