Skip to content

Conversation

@elenatanasoiu
Copy link
Contributor

Discovered by @shati-patel here.

The getFirstStoragePath() method would break on windows:

Path contains invalid characters: /c:/git-repo/codespaces-codeql (codeQL.createSkeletonQuery)

This makes sense, since we're looking to get the parent folder by splitting for /. In Windows, paths use \ instead of /. So let's detect the platform and add a test for this case.

The `getFirstStoragePath()` method would break on windows:

```
Path contains invalid characters: /c:/git-repo/codespaces-codeql (codeQL.createSkeletonQuery)
```

This makes sense, since we're looking to get the parent folder by splitting for `/`.

In windows, paths use `\` instead of `/`.

So let's detect the platform and add a test for this case.
@elenatanasoiu elenatanasoiu force-pushed the elena/yer-a-windows-query branch from 14fb1b5 to 3087886 Compare April 12, 2023 09:47
@shati-patel
Copy link
Contributor

shati-patel commented Apr 12, 2023

Elena & I paired on testing this on Windows—just double-checking that the fix works in the starter workspace too, and then I'll push up the changes! 🙌🏽

We now use `fsPath` instead of `path`.

Note: I haven't yet fixed the tests, nor checked manually on mac/linux

Tangential change: we now use the `dirname` method, instead of manually splitting paths to get a parent folder.
This should be covered by running the general test suite in CI (on windows-latest)
@elenatanasoiu
Copy link
Contributor Author

elenatanasoiu commented Apr 12, 2023

Thanks for fixing this up Shati ❤️ I've just tested this and it downloads the database successfully on Mac as well + creates the QL pack!

There's one more thing we need to solve here now that we've made it work on Mac + Windows: we're downloading the database as a workspace folder (see screenshot) when it should actually be using the workspaceStorage folder (e.g. /Users/<>/Library/Application Support/Code/User/workspaceStorage/0bbefad4b919c9a4116bab45b1eef1ec/GitHub.vscode-codeql). This is the folder we pass in when we call downloadGitHubDatabase and it's taken off ctx.storagePath.fsPath.

Screenshot 2023-04-12 at 14 21 16

I think what we want to do is use two separate paths:

  1. for creating folders we use getFirstStoragePath()
  2. for creating databases we'll need to pass ctx.storageUri.fsPath down from the extension (like I was doing here before I reversed it).

Not sure how much more time you want to spend on this. I'm happy to add an extra commit to separate the two paths but if you want to take the reins, let me know.

@elenatanasoiu elenatanasoiu marked this pull request as draft April 12, 2023 13:54
@elenatanasoiu elenatanasoiu force-pushed the elena/yer-a-windows-query branch from e66ad99 to 58c808f Compare April 12, 2023 14:26
@elenatanasoiu
Copy link
Contributor Author

I've added two extra commits to split out:

  • the path we use for creating QL pack folders (qlPackFolderPath)
  • the path we use for downloading databases (databaseStoragePath)

I've tested this on Mac for codespaces-codeql & the starter workspace.

@elenatanasoiu elenatanasoiu marked this pull request as ready for review April 12, 2023 14:42
@elenatanasoiu elenatanasoiu requested a review from a team April 12, 2023 14:43
private readonly databaseUI: DatabaseUI,
private readonly localQueryResultsView: ResultsView,
private readonly queryStorageDir: string,
private readonly ctx: ExtensionContext,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use App here to avoid introducing new dependencies on the ExtensionContext? That should also contain a workspaceStoragePath and globalStoragePath as strings which shortens the code below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Have pushed a change to use App.

Now that we've figured out how to set the storage path for both Mac &
Windows, we also want to make sure we're consistent with the location
where we save databases.

At the moment, our change will download databases directly in the
workspace folder.

When we call `downloadGitHubDatabase()` in other places outside the
wizard, we provide `ctx.storageUri.fsPath` as the location. [1] [2] [3]

Let's do the same here.

I've tested this on Mac for the codespaces-codeql & starter workspaces.

[1]: https://github.com/github/vscode-codeql/blob/c7bb22c312d4bbe46d90ff0a43e9cff22c6bd5ed/extensions/ql-vscode/src/local-databases-ui.ts#L476
[2]: https://github.com/github/vscode-codeql/blob/c7bb22c312d4bbe46d90ff0a43e9cff22c6bd5ed/extensions/ql-vscode/src/extension.ts#L710
[3]: https://github.com/github/vscode-codeql/blob/c7bb22c312d4bbe46d90ff0a43e9cff22c6bd5ed/extensions/ql-vscode/src/extension.ts#L1120
@elenatanasoiu elenatanasoiu force-pushed the elena/yer-a-windows-query branch from 58c808f to e298f2b Compare April 12, 2023 16:39
Base automatically changed from elena/improvements-to-wizard to main April 12, 2023 17:08
@elenatanasoiu elenatanasoiu merged commit 03adb70 into main Apr 13, 2023
@elenatanasoiu elenatanasoiu deleted the elena/yer-a-windows-query branch April 13, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants