Skip to content

Commit 7d02bd6

Browse files
committed
Avoid unconfiguring the CLI
The only times we call configureCli are: 1. When logging in, where we always have a token/URL. 2. When opening a link, where the token might be undefined, but if so we want to use the current token; not wipe it. Since in neither of these cases do we want to remove the URL or token, just remove that code altogether so that updating with undefined is a no-op. Fixes #318.
1 parent a6383d9 commit 7d02bd6

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
- Avoid deleting the existing token when launching with a link that omits the
8+
token.
9+
510
## [v1.3.0](https://github.com/coder/vscode-coder/releases/tag/v1.3.0) (2024-07-01)
611

712
### Added

src/storage.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -434,40 +434,40 @@ export class Storage {
434434

435435
/**
436436
* Configure the CLI for the deployment with the provided label.
437+
*
438+
* Falsey values are a no-op; we avoid unconfiguring the CLI to avoid breaking
439+
* existing connections.
437440
*/
438441
public async configureCli(label: string, url: string | undefined, token: string | undefined | null) {
439442
await Promise.all([this.updateUrlForCli(label, url), this.updateTokenForCli(label, token)])
440443
}
441444

442445
/**
443-
* Update or remove the URL for the deployment with the provided label on disk
444-
* which can be used by the CLI via --url-file.
446+
* Update the URL for the deployment with the provided label on disk which can
447+
* be used by the CLI via --url-file. If the URL is falsey, do nothing.
445448
*
446449
* If the label is empty, read the old deployment-unaware config instead.
447450
*/
448451
private async updateUrlForCli(label: string, url: string | undefined): Promise<void> {
449-
const urlPath = this.getUrlPath(label)
450452
if (url) {
453+
const urlPath = this.getUrlPath(label)
451454
await fs.mkdir(path.dirname(urlPath), { recursive: true })
452455
await fs.writeFile(urlPath, url)
453-
} else {
454-
await fs.rm(urlPath, { force: true })
455456
}
456457
}
457458

458459
/**
459-
* Update or remove the session token for a deployment with the provided label
460-
* on disk which can be used by the CLI via --session-token-file.
460+
* Update the session token for a deployment with the provided label on disk
461+
* which can be used by the CLI via --session-token-file. If the token is
462+
* falsey, do nothing.
461463
*
462464
* If the label is empty, read the old deployment-unaware config instead.
463465
*/
464466
private async updateTokenForCli(label: string, token: string | undefined | null) {
465-
const tokenPath = this.getSessionTokenPath(label)
466467
if (token) {
468+
const tokenPath = this.getSessionTokenPath(label)
467469
await fs.mkdir(path.dirname(tokenPath), { recursive: true })
468470
await fs.writeFile(tokenPath, token)
469-
} else {
470-
await fs.rm(tokenPath, { force: true })
471471
}
472472
}
473473

0 commit comments

Comments
 (0)