Skip to content

Commit e4efcb3

Browse files
committed
Drive letter on Windows remotes
Fixes microsoft#135762
1 parent 4297ff8 commit e4efcb3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/vs/base/common/extpath.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ export function isRootOrDriveLetter(path: string): boolean {
300300
return pathNormalized === posix.sep;
301301
}
302302

303-
export function hasDriveLetter(path: string): boolean {
304-
if (isWindows) {
303+
export function hasDriveLetter(path: string, continueAsWindows?: boolean): boolean {
304+
const isWindowsPath: boolean = ((continueAsWindows !== undefined) ? continueAsWindows : isWindows);
305+
if (isWindowsPath) {
305306
return isWindowsDriveLetter(path.charCodeAt(0)) && path.charCodeAt(1) === CharCode.Colon;
306307
}
307308

src/vs/base/common/labels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export function getBaseLabel(resource: URI | string | undefined): string | undef
9292
return base;
9393
}
9494

95-
export function normalizeDriveLetter(path: string): string {
96-
if (hasDriveLetter(path)) {
95+
export function normalizeDriveLetter(path: string, continueAsWindows?: boolean): string {
96+
if (hasDriveLetter(path, continueAsWindows)) {
9797
return path.charAt(0).toUpperCase() + path.slice(1);
9898
}
9999

src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export class SimpleFileDialog {
116116
private autoCompletePathSegment: string = '';
117117
private activeItem: FileQuickPickItem | undefined;
118118
private userHome!: URI;
119+
private isWindows: boolean = false;
119120
private badPath: string | undefined;
120121
private remoteAgentEnvironment: IRemoteAgentEnvironment | null | undefined;
121122
private separator: string = '/';
@@ -251,6 +252,7 @@ export class SimpleFileDialog {
251252
this.allowFileSelection = !!this.options.canSelectFiles;
252253
this.separator = this.labelService.getSeparator(this.scheme, this.remoteAuthority);
253254
this.hidden = false;
255+
this.isWindows = await this.checkIsWindowsOS();
254256
let homedir: URI = this.options.defaultUri ? this.options.defaultUri : this.workspaceContextService.getWorkspace().folders[0].uri;
255257
let stat: IFileStat | undefined;
256258
let ext: string = resources.extname(homedir);
@@ -780,7 +782,7 @@ export class SimpleFileDialog {
780782
// Show a yes/no prompt
781783
const message = nls.localize('remoteFileDialog.validateExisting', '{0} already exists. Are you sure you want to overwrite it?', resources.basename(uri));
782784
return this.yesNoPrompt(uri, message);
783-
} else if (!(isValidBasename(resources.basename(uri), await this.isWindowsOS()))) {
785+
} else if (!(isValidBasename(resources.basename(uri), this.isWindows))) {
784786
// Filename not allowed
785787
this.filePickBox.validationMessage = nls.localize('remoteFileDialog.validateBadFilename', 'Please enter a valid file name.');
786788
return Promise.resolve(false);
@@ -794,7 +796,7 @@ export class SimpleFileDialog {
794796
// File or folder doesn't exist
795797
this.filePickBox.validationMessage = nls.localize('remoteFileDialog.validateNonexistentDir', 'Please enter a path that exists.');
796798
return Promise.resolve(false);
797-
} else if (uri.path === '/' && (await this.isWindowsOS())) {
799+
} else if (uri.path === '/' && this.isWindows) {
798800
this.filePickBox.validationMessage = nls.localize('remoteFileDialog.windowsDriveLetter', 'Please start the path with a drive letter.');
799801
return Promise.resolve(false);
800802
} else if (stat.isDirectory && !this.allowFolderSelection) {
@@ -871,7 +873,7 @@ export class SimpleFileDialog {
871873
}
872874

873875
private pathFromUri(uri: URI, endWithSeparator: boolean = false): string {
874-
let result: string = normalizeDriveLetter(uri.fsPath).replace(/\n/g, '');
876+
let result: string = normalizeDriveLetter(uri.fsPath, this.isWindows).replace(/\n/g, '');
875877
if (this.separator === '/') {
876878
result = result.replace(/\\/g, this.separator);
877879
} else {
@@ -892,7 +894,7 @@ export class SimpleFileDialog {
892894
}
893895
}
894896

895-
private async isWindowsOS(): Promise<boolean> {
897+
private async checkIsWindowsOS(): Promise<boolean> {
896898
let isWindowsOS = isWindows;
897899
const env = await this.getRemoteAgentEnvironment();
898900
if (env) {

0 commit comments

Comments
 (0)