Repository navigation
Fix updating globaljsonworkloadsets.json - #50372
Conversation
globaljsonworkloadsets.json
|
I had just discovered this issue with my MAUI workloads and thought I was bumping the MAUI issue when I discovered the broken file here. Turns out it was @Redth repo (tagging to see if we can get some eyes on this) and no the MAUI one. Looking for a MAUI issue I came across this one. It is funny that this is what the bug is, because that is a thing that came up recently with image croppers across different platforms writing new data but not truncating the file leaving the old data recoverable. |
|
Hey @baronfel, unsure if you are the right person to tag of not. Would it be possible to get some eyes on this issue? I think this has mostly flown under the radar because string versions are currently I am unsure if the PR is the exact fix or if it needs to be fixed elsewhere as I am unsure how to test the SDK. Fun fact: this is the same type of bug that led to Android (and other platforms) leaking data from cropped images because they were not truncating the file before writing. |
|
Due to lack of recent activity, this PR has been labeled as 'Stale'. It will be closed if no further activity occurs within 7 more days. Any new comment will remove the label. |
|
This is still broken and bringing down CI/CD every now and then. I don't know if the above fix has been tested. |
|
/backport to release/11.0.2xx |
|
Started backporting to |
|
Thank you for this fix and analysis! |
|
@baronfel backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix updating 'globaljsonworkloadsets.json'
Using index info to reconstruct a base tree...
M src/Cli/dotnet/Commands/Workload/GlobalJsonWorkloadSetFile.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/dotnet/Commands/Workload/GlobalJsonWorkloadSetFile.cs
Applying: Remove unnecessary Seek
Using index info to reconstruct a base tree...
M src/Cli/dotnet/Commands/Workload/GlobalJsonWorkloadSetFile.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/dotnet/Commands/Workload/GlobalJsonWorkloadSetFile.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Workload/GlobalJsonWorkloadSetFile.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Remove unnecessary Seek
Error: The process '/usr/bin/git' failed with exit code 128 |
|
@baronfel Would it be possible to backport this to the SDK 10.0.x as well? |
|
For anyone else finding this thread I'll leave this extra bit of info I have been fighting with. If you are on macOS and you are trying out dotnetup then you should not touch |
|
Another nugget for those who have CI/CD. I added this to my pipelines/githubactions file. For us this is where our - pwsh: |
# Find globaljsonworkloadsets.json
$globalJsonWorkloadSets = "$env:DOTNET_ROOT/metadata/workloads/Arm64/10.0.400/InstallState/globaljsonworkloadsets.json"
# If it exists load the json content
if (Test-Path -LiteralPath $globalJsonWorkloadSets -PathType Leaf) {
$globalJsonWorkloadSetsContent = Get-Content -LiteralPath $globalJsonWorkloadSets -Raw
# Count the number of }
$closingBraceCount = [regex]::Matches($globalJsonWorkloadSetsContent, '\}').Count
# If there is more than 1 delete everything after that 1 and save the file.
if ($closingBraceCount -gt 1) {
$firstClosingBrace = $globalJsonWorkloadSetsContent.IndexOf('}')
[System.IO.File]::WriteAllText($globalJsonWorkloadSets, $globalJsonWorkloadSetsContent.Substring(0, $firstClosingBrace + 1))
}
}
displayName: 'Repair globaljsonworkloadsets.json' |
Current logic sets the file stream position to 0, and overwrites the content of the
globaljsonworkloadsets.jsonfile.If the new content is shorter, then some characters remain from the old content, thus making the JSON malformed.
Example
workloadVersioninglobal.jsonto9.0.303.1.dotnet workload restoremakes the content ofglobaljsonworkloadsets.jsonthe following:{ "<path-to-global-json>": "9.0.303.1" }workloadVersioninglobal.jsonto9.0.304.dotnet workload restoreoutputs this warning:and makes the content of
globaljsonworkloadsets.jsonthe following:{ "<path-to-global-json>": "9.0.304" } }The new version number is 2 characters shorter, so 2 characters from the old content of the file remains.
This is not a valid JSON and causes any subsequent
dotnet workload restorecommand to fail with error:Fix
This fix sets the stream length to 0, truncating the stream, so there will be no remainder of the old content.
Also, as per
SetLengthdocumentation:if the current position is greater than the new length, the current position is moved to the last byte of the stream, soSeekis unnecessary.