Store state of CodeQL distribution on filesystem instead of in globalState#3762
Merged
Store state of CodeQL distribution on filesystem instead of in globalState#3762
globalState#3762Conversation
Contributor
robertbrignull
left a comment
There was a problem hiding this comment.
I want to do a little bit of manual testing but as an approach it looks reasonable to me, and I like that we're using a library for the lock file instead of writing our own handler for that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
globalStateis shared between all VS Code instances, regardless of whether they are local or remote (e.g. Codespaces, SSH). Since the distribution (i.e. the CodeQL CLI) is stored on the filesystem, this does not always match theglobalState(e.g. when switching between local and Codespaces).This fixes that problem by also storing the distribution state on the local filesystem in a
distribution.jsonfile. This file contains the same information as theglobalStatedid, but is local to each filesystem. For example, this is what it contains on my machine:{ "folderIndex": 244, "release": { "assets": [ { "id": 196506420, "name": "codeql-linux64.zip", "size": 725141406 }, { "id": 196506419, "name": "codeql-linux64.zip.checksum.txt", "size": 85 }, { "id": 196506418, "name": "codeql-osx64.zip", "size": 944929533 }, { "id": 196506422, "name": "codeql-osx64.zip.checksum.txt", "size": 83 }, { "id": 196506421, "name": "codeql-win64.zip", "size": 345891346 }, { "id": 196506424, "name": "codeql-win64.zip.checksum.txt", "size": 83 }, { "id": 196506416, "name": "codeql.zip", "size": 1745315855 } ], "createdAt": "2024-10-04T20:51:14Z", "id": 178107771, "name": "v2.19.1" } }The migration to this format is quite trivial: if the
distribution.jsonfile doesn't exist, take the values fromglobalStateand create it. We can then always use thedistribution.jsonfile.In addition, this adds a filesystem-based lock when updating the distribution. This ensures that there are no race conditions between multiple VS Code instances when they all try to update the distribution.