Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspace: normalize paths of workspace roots #7598

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/workspace/src/browser/workspace-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ describe('WorkspaceService', () => {
expect((<Map<string, Disposable>>wsService['rootWatchers']).has(rootB)).to.be.true;
});

it(
'should resolve a relative workspace root path to a normalized root path',
async () => {
const workspaceFilePath = '/home/workspaceFile';
const workspaceFileUri = 'file://' + workspaceFilePath;
const workspaceFileStat = <FileStat>{
uri: workspaceFileUri,
lastModification: 0,
isDirectory: false
};
const rootRelative = '../workspace';
const rootActual = 'file:///workspace';
(<sinon.SinonStub>mockWorkspaceServer.getMostRecentlyUsedWorkspace).resolves(workspaceFileStat.uri);
const stubGetFileStat = (<sinon.SinonStub>mockFilesystem.getFileStat);
stubGetFileStat.withArgs(workspaceFileUri).resolves(workspaceFileStat);
(<sinon.SinonStub>mockFilesystem.exists).resolves(true);
(<sinon.SinonStub>mockFilesystem.resolveContent).resolves({
stat: workspaceFileStat,
content: `{"folders":[{"path":"${rootRelative}"}],"settings":{}}`
});
stubGetFileStat.withArgs(rootActual).resolves(<FileStat>{
uri: rootActual, lastModification: 0, isDirectory: true
});
(<sinon.SinonStub>mockFileSystemWatcher.watchFileChanges).resolves(new DisposableCollection());

await wsService['init']();
expect(wsService.workspace).to.eq(workspaceFileStat);
expect((await wsService.roots).length).to.eq(1);
expect(wsService.tryGetRoots().length).to.eq(1);
expect(wsService.tryGetRoots()[0].uri).to.eq(rootActual);
});

it('should set the exposed roots an empty array if the workspace file stores invalid workspace data', async () => {
const workspaceFileUri = 'file:///home/workspaceFile';
const workspaceFileStat = <FileStat>{
Expand Down
3 changes: 2 additions & 1 deletion packages/workspace/src/browser/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ export class WorkspaceService implements FrontendApplicationContribution {
if (uriStr.endsWith('/')) {
uriStr = uriStr.slice(0, -1);
}
const fileStat = await this.fileSystem.getFileStat(uriStr);
const normalizedUriStr = new URI(uriStr).normalizePath().toString();
const fileStat = await this.fileSystem.getFileStat(normalizedUriStr);
if (!fileStat) {
return undefined;
}
Expand Down