[release/8.0-staging] Don't use File.OpenWrite when trying to overwrite a file in illink/wasm build tasks #93854
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.
Backport of #93744
File.OpenWrite will open an existing file and not truncate existing data, this can lead to unexpected results if the new data is shorter than the existing data.
Customer Impact
illink has a feature to dump a dependency analysis xml during the build and when you run another build after making a change that'd reduce dependencies the xml would get corrupted since it wrote less data than the existing file had.
The fix is to use the FileMode.Create option in cases where the intention is to create a new file or overwrite an existing one.
I noticed another instance of this in the Wasm build tasks so fixed it there as well.
Testing
Verified an existing file gets overwritten as expected.
Risk
Low