Skip to content

Commit 40d6d4b

Browse files
committed
Fix session and log directories when user folder is on UNC share
When we moved to using `globalStorageUri` and passing `vscode.Uri`s around, we did not test UNC shares. It turns out that while `vscode.Uri.fsPath`'s documentation says that it "does not look at scheme," it actually does look at the scheme and essentially requires it to be `file`. The scheme of the `globalStorageUri` however is `vscode-userdata`, so the `fsPath` fails to then handle the UNC share path. We are now replacing the scheme with `file` to get around this bug.
1 parent 9511e8c commit 40d6d4b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/features/ExternalApi.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ export class ExternalApiFeature extends LanguageClientConsumer implements IPower
169169
}
170170

171171
public getStorageUri(): vscode.Uri {
172-
return this.extensionContext.globalStorageUri;
172+
// We have to override the scheme because it defaults to
173+
// 'vscode-userdata' which breaks UNC paths.
174+
return this.extensionContext.globalStorageUri.with({ scheme: "file"});
173175
}
174176

175177
public dispose() {

src/logging.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ export class Logger implements ILogger {
4040
constructor(logLevelName: string, globalStorageUri: vscode.Uri) {
4141
this.logLevel = Logger.logLevelNameToValue(logLevelName);
4242
this.logChannel = vscode.window.createOutputChannel("PowerShell Extension Logs");
43+
// We have to override the scheme because it defaults to
44+
// 'vscode-userdata' which breaks UNC paths.
4345
this.logDirectoryPath = vscode.Uri.joinPath(
44-
globalStorageUri,
46+
globalStorageUri.with({ scheme: "file" }),
4547
"logs",
4648
`${Math.floor(Date.now() / 1000)}-${vscode.env.sessionId}`);
4749
this.logFilePath = this.getLogFilePath("vscode-powershell");

src/session.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export class SessionManager implements Middleware {
111111

112112
// Create the language status item
113113
this.languageStatusItem = this.createStatusBarItem();
114-
this.sessionsFolder = vscode.Uri.joinPath(extensionContext.globalStorageUri, "sessions");
114+
// We have to override the scheme because it defaults to
115+
// 'vscode-userdata' which breaks UNC paths.
116+
this.sessionsFolder = vscode.Uri.joinPath(extensionContext.globalStorageUri.with({ scheme: "file"}), "sessions");
115117
this.platformDetails = getPlatformDetails();
116118
this.HostName = hostName;
117119
this.HostVersion = hostVersion;

0 commit comments

Comments
 (0)