Skip to content

Commit 1615a36

Browse files
committed
Multi root workspaces: UNC paths get written as URI and not path. Fixes microsoft#70453
1 parent 528526d commit 1615a36

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/vs/base/common/resources.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,15 @@ export function relativePath(from: URI, to: URI): string | undefined {
218218
* Resolves a absolute or relative path against a base URI.
219219
*/
220220
export function resolvePath(base: URI, path: string): URI {
221-
let resolvedPath: string;
222221
if (base.scheme === Schemas.file) {
223-
resolvedPath = URI.file(paths.resolve(originalFSPath(base), path)).path;
224-
} else {
225-
resolvedPath = paths.posix.resolve(base.path, path);
222+
const newURI = URI.file(paths.resolve(originalFSPath(base), path));
223+
return base.with({
224+
authority: newURI.authority,
225+
path: newURI.path
226+
});
226227
}
227228
return base.with({
228-
path: resolvedPath
229+
path: paths.posix.resolve(base.path, path)
229230
});
230231
}
231232

src/vs/base/test/common/resources.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ suite('Resources', () => {
296296

297297
assertResolve(URI.file('\\\\server\\share\\some\\'), 'b1\\file.js', URI.file('\\\\server\\share\\some\\b1\\file.js'));
298298
assertResolve(URI.file('\\\\server\\share\\some\\'), '\\file.js', URI.file('\\\\server\\share\\file.js'));
299+
300+
assertResolve(URI.file('c:\\'), '\\\\server\\share\\some\\', URI.file('\\\\server\\share\\some'));
301+
assertResolve(URI.file('\\\\server\\share\\some\\'), 'c:\\', URI.file('c:\\'));
299302
} else {
300303
assertResolve(URI.file('/foo/bar'), 'file.js', URI.file('/foo/bar/file.js'));
301304
assertResolve(URI.file('/foo/bar'), './file.js', URI.file('/foo/bar/file.js'));

src/vs/platform/workspaces/common/workspaces.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const SLASH = '/';
173173
*/
174174
export function getStoredWorkspaceFolder(folderURI: URI, folderName: string | undefined, targetConfigFolderURI: URI, useSlashForPath = !isWindows): IStoredWorkspaceFolder {
175175

176-
if (folderURI.scheme !== targetConfigFolderURI.scheme || !isEqualAuthority(folderURI.authority, targetConfigFolderURI.authority)) {
176+
if (folderURI.scheme !== targetConfigFolderURI.scheme) {
177177
return { name: folderName, uri: folderURI.toString(true) };
178178
}
179179

@@ -200,6 +200,9 @@ export function getStoredWorkspaceFolder(folderURI: URI, folderName: string | un
200200
}
201201
}
202202
} else {
203+
if (!isEqualAuthority(folderURI.authority, targetConfigFolderURI.authority)) {
204+
return { name: folderName, uri: folderURI.toString(true) };
205+
}
203206
folderPath = folderURI.path;
204207
}
205208
}

src/vs/platform/workspaces/test/electron-main/workspacesMainService.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,31 @@ suite('WorkspacesMainService', () => {
316316
});
317317
});
318318

319+
test('rewriteWorkspaceFileForNewLocation (unc paths)', () => {
320+
if (!isWindows) {
321+
return Promise.resolve();
322+
}
323+
324+
const workspaceLocation = path.join(os.tmpdir(), 'wsloc');
325+
const folder1Location = 'x:\\foo';
326+
const folder2Location = '\\\\server\\share2\\some\\path';
327+
const folder3Location = path.join(os.tmpdir(), 'wsloc', 'inner', 'more');
328+
329+
return createWorkspace([folder1Location, folder2Location, folder3Location]).then(workspace => {
330+
const workspaceConfigPath = URI.file(path.join(workspaceLocation, `myworkspace.${Date.now()}.${WORKSPACE_EXTENSION}`));
331+
let origContent = fs.readFileSync(workspace.configPath.fsPath).toString();
332+
333+
const newContent = rewriteWorkspaceFileForNewLocation(origContent, workspace.configPath, workspaceConfigPath);
334+
335+
const ws = JSON.parse(newContent) as IStoredWorkspace;
336+
assertPathEquals((<IRawFileWorkspaceFolder>ws.folders[0]).path, folder1Location);
337+
assertPathEquals((<IRawFileWorkspaceFolder>ws.folders[1]).path, folder2Location);
338+
assertPathEquals((<IRawFileWorkspaceFolder>ws.folders[2]).path, 'inner\\more');
339+
340+
service.deleteUntitledWorkspaceSync(workspace);
341+
});
342+
});
343+
319344
test('deleteUntitledWorkspaceSync (untitled)', () => {
320345
return createWorkspace([process.cwd(), os.tmpdir()]).then(workspace => {
321346
assert.ok(fs.existsSync(workspace.configPath.fsPath));

0 commit comments

Comments
 (0)