Support cancellation of download checksums #3778
Merged
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.
Problem
Cause
The validation step doesn't support cancellation (even though we included it in the low-level
ComputeHash
extension function in #3659), so when the second install attempt starts, the original validation is still happening, and another one starts up in parallel. Then one thread (probably the first one that the user tried to cancel) finishes and tries to copy the temp file to the cache and delete it. But the other thread is still validating the temp file, so the deletion attempt throws an exception (on Windows, which locks files that are in use).Changes
Now if the user clicks cancel while a mod is being validated, validation will stop before the file is copied to cache and deleted, so future install attempts can proceed without being blocked by another thread.
The file will be left in the in-progress download folder because there's most likely nothing wrong with it, and if there is something wrong, it will be caught in any future validation attempts.
Fixes #3777.
Known limitations
NetFileCache.ZipValid
can't be cancelled, becauseZipFile.TestArchive
can't be cancelled. So if the user tries to cancel while this is in progress, it will finish that step, and then the cancellation happens afterwards before the SHA1 check starts. This should still be fine since the deletion attempt will no longer occur.(The SHA1 and SHA256 checks are both immediately cancellable.)