diff --git a/src/client/common/platform/fileSystem.ts b/src/client/common/platform/fileSystem.ts index 462c6f737fa1..d745d2408d03 100644 --- a/src/client/common/platform/fileSystem.ts +++ b/src/client/common/platform/fileSystem.ts @@ -107,10 +107,6 @@ export class FileSystem implements IFileSystem { return this.pathUtils.arePathsSame(path1, path2); } - public getRealPath(filePath: string): Promise { - return this.pathUtils.getRealPath(filePath); - } - //================================= // "raw" operations diff --git a/src/client/common/platform/fs-paths.ts b/src/client/common/platform/fs-paths.ts index c27bd3e8418c..fc1b7fc670e8 100644 --- a/src/client/common/platform/fs-paths.ts +++ b/src/client/common/platform/fs-paths.ts @@ -1,13 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import * as fs from 'fs-extra'; import * as nodepath from 'path'; import { getOSType, OSType } from '../utils/platform'; // prettier-ignore import { IExecutables, - IFileSystemPaths + IFileSystemPaths, IFileSystemPathUtils } from './types'; // tslint:disable-next-line:no-var-requires no-require-imports const untildify = require('untildify'); @@ -21,8 +20,7 @@ interface INodePath { normalize(filename: string): string; } -// The file path operations used by the extension. -export class FileSystemPaths { +export class FileSystemPaths implements IFileSystemPaths { // prettier-ignore constructor( private readonly isCaseInsensitive: boolean, @@ -74,10 +72,6 @@ export class FileSystemPaths { } } -// Where to fine executables. -// -// In particular this class provides all the tools needed to find -// executables, including through an environment variable. export class Executables { // prettier-ignore constructor( @@ -108,8 +102,7 @@ interface IRawPaths { relative(relpath: string, rootpath: string): string; } -// A collection of high-level utilities related to filesystem paths. -export class FileSystemPathUtils { +export class FileSystemPathUtils implements IFileSystemPathUtils { // prettier-ignore constructor( public readonly home: string, @@ -136,26 +129,12 @@ export class FileSystemPathUtils { ); } - // Return true if the two paths are equivalent on the current - // filesystem and false otherwise. On Windows this is significant. - // On non-Windows the filenames must always be exactly the same. public arePathsSame(path1: string, path2: string): boolean { path1 = this.paths.normCase(path1); path2 = this.paths.normCase(path2); return path1 === path2; } - // Return the canonicalized absolute filename. - public async getRealPath(filename: string): Promise { - try { - return await fs.realpath(filename); - } catch { - // We ignore the error. - return filename; - } - } - - // Return the clean (displayable) form of the given filename. public getDisplayName(filename: string, cwd?: string): string { if (cwd && filename.startsWith(cwd)) { return `.${this.paths.sep}${this.raw.relative(cwd, filename)}`; diff --git a/src/client/common/platform/types.ts b/src/client/common/platform/types.ts index c0541fb8298c..bbf3ce4cf55d 100644 --- a/src/client/common/platform/types.ts +++ b/src/client/common/platform/types.ts @@ -50,6 +50,7 @@ export type TemporaryDirectory = { path: string } & vscode.Disposable; //=========================== // FS paths +// The low-level file path operations used by the extension. export interface IFileSystemPaths { readonly sep: string; join(...filenames: string[]): string; @@ -59,15 +60,25 @@ export interface IFileSystemPaths { normCase(filename: string): string; } +// Where to fine executables. +// +// In particular this class provides all the tools needed to find +// executables, including through an environment variable. export interface IExecutables { delimiter: string; envVar: string; } +// A collection of high-level utilities related to filesystem paths. export interface IFileSystemPathUtils { readonly paths: IFileSystemPaths; readonly executables: IExecutables; + readonly home: string; + // Return true if the two paths are equivalent on the current + // filesystem and false otherwise. On Windows this is significant. + // On non-Windows the filenames must always be exactly the same. arePathsSame(path1: string, path2: string): boolean; + // Return the clean (displayable) form of the given filename. getDisplayName(pathValue: string, cwd?: string): string; } @@ -83,7 +94,6 @@ export interface IFileSystem { // path-related directorySeparatorChar: string; arePathsSame(path1: string, path2: string): boolean; - getRealPath(path: string): Promise; // "raw" operations stat(filePath: string): Promise; diff --git a/src/test/common/platform/filesystem.functional.test.ts b/src/test/common/platform/filesystem.functional.test.ts index bb8a07a141c7..540b433dd438 100644 --- a/src/test/common/platform/filesystem.functional.test.ts +++ b/src/test/common/platform/filesystem.functional.test.ts @@ -69,19 +69,6 @@ suite('FileSystem', () => { expect(areSame).to.equal(expected); }); }); - - suite('getRealPath', () => { - // tested fully in the FileSystemPathUtils tests. - - test('matches wrapped object', async () => { - const filename = fixPath('a/b/c/spam.py'); - const expected = await pathUtils.getRealPath(filename); - - const resolved = await fileSystem.getRealPath(filename); - - expect(resolved).to.equal(expected); - }); - }); }); suite('raw', () => { diff --git a/src/test/common/platform/fs-paths.functional.test.ts b/src/test/common/platform/fs-paths.functional.test.ts index b90bf3faadc2..e45bf3f51c36 100644 --- a/src/test/common/platform/fs-paths.functional.test.ts +++ b/src/test/common/platform/fs-paths.functional.test.ts @@ -14,10 +14,7 @@ import { FileSystemPaths, FileSystemPathUtils } from '../../../client/common/platform/fs-paths'; -// prettier-ignore -import { - fixPath, FSFixture, OSX, SUPPORTS_SYMLINKS, WINDOWS as IS_WINDOWS -} from './utils'; +import { WINDOWS as IS_WINDOWS } from './utils'; suite('FileSystem - Paths', () => { let paths: FileSystemPaths; @@ -186,10 +183,8 @@ suite('FileSystem - Executables', () => { suite('FileSystem - Path Utils', () => { let utils: FileSystemPathUtils; - let fix: FSFixture; setup(() => { utils = FileSystemPathUtils.withDefaults(); - fix = new FSFixture(); }); suite('arePathsSame', () => { @@ -231,139 +226,6 @@ suite('FileSystem - Path Utils', () => { }); }); - suite('getRealPath', () => { - const prevCwd = process.cwd(); - let cwd: string; - setup(async function() { - if (OSX) { - // tslint:disable-next-line:no-suspicious-comment - // TODO(GH-8995) These tests are failing on Mac, so - // we are temporarily disabling it. - // tslint:disable-next-line:no-invalid-this - return this.skip(); - } - cwd = await fix.createDirectory('x/y/z'); - process.chdir(cwd); - }); - teardown(() => { - process.chdir(prevCwd); - }); - - test('basename-only', async () => { - const expected = await fix.createFile('x/y/z/spam.py'); - - const resolved = await utils.getRealPath('spam.py'); - - expect(resolved).to.equal(expected); - }); - - test('absolute', async () => { - const filename = await fix.createFile('spam.py'); - const expected = filename; - - const resolved = await utils.getRealPath(filename); - - expect(resolved).to.equal(expected); - }); - - test('relative', async () => { - const expected = await fix.createFile('x/y/z/w/spam.py'); - const relpath = fixPath('./w/spam.py'); - - const resolved = await utils.getRealPath(relpath); - - expect(resolved).to.equal(expected); - }); - - test('parent', async () => { - const expected = await fix.resolve('x/y'); - - const resolved = await utils.getRealPath('..'); - - expect(resolved).to.equal(expected); - }); - - test('cousin', async () => { - const expected = await fix.createFile('x/w/spam.py'); - const relpath = fixPath('../../w/spam.py'); - - const resolved = await utils.getRealPath(relpath); - - expect(resolved).to.equal(expected); - }); - - test('does not exist', async () => { - const resolved = await utils.getRealPath('spam.py'); - - // The original path was returned unchanged. - expect(resolved).to.equal('spam.py'); // instead of /x/y/z/spam.py - }); - - test('directory does not exist', async () => { - const relpath = fixPath('../../w/spam.py'); - - const resolved = await utils.getRealPath(relpath); - - // The original path was returned unchanged. - expect(resolved).to.equal(relpath); // instead of /x/w/spam.py - }); - - test('symlink', async function() { - if (!SUPPORTS_SYMLINKS) { - // tslint:disable-next-line:no-invalid-this - this.skip(); - } - const expected = await fix.createFile('spam.py'); - await fix.createSymlink('x/y/z/eggs.py', expected); - - const resolved = await utils.getRealPath('eggs.py'); - - expect(resolved).to.equal(expected); - }); - - test('symlink chain', async function() { - if (!SUPPORTS_SYMLINKS) { - // tslint:disable-next-line:no-invalid-this - this.skip(); - } - const expected = await fix.createFile('w/spam.py'); - const symlink1 = await fix.createSymlink('x/y/spam.py', expected); - await fix.createSymlink('x/y/z/eggs.py', symlink1); - - const resolved = await utils.getRealPath('eggs.py'); - - expect(resolved).to.equal(expected); - }); - - test('symlink (target does not exist)', async function() { - if (!SUPPORTS_SYMLINKS) { - // tslint:disable-next-line:no-invalid-this - this.skip(); - } - const filename = await fix.resolve('spam.py'); - await fix.createSymlink('x/y/z/eggs.py', filename); - - const resolved = await utils.getRealPath('eggs.py'); - - // The original path was returned unchanged. - expect(resolved).to.equal('eggs.py'); // instead of /spam.py - }); - - test('mixed', async function() { - if (!SUPPORTS_SYMLINKS) { - // tslint:disable-next-line:no-invalid-this - this.skip(); - } - const expected = await fix.createFile('x/y/w/eggs.py'); - await fix.createSymlink('x/w/spam.py', expected); - const relpath = fixPath('../../w/spam.py'); - - const resolved = await utils.getRealPath(relpath); - - expect(resolved).to.equal(expected); - }); - }); - suite('getDisplayName', () => { const relname = path.join('spam', 'eggs', 'spam.py'); const cwd = path.resolve(path.sep, 'x', 'y', 'z'); diff --git a/src/test/configuration/interpreterSelector.unit.test.ts b/src/test/configuration/interpreterSelector.unit.test.ts index addf61b1fa07..d9945e05b017 100644 --- a/src/test/configuration/interpreterSelector.unit.test.ts +++ b/src/test/configuration/interpreterSelector.unit.test.ts @@ -81,7 +81,6 @@ suite('Interpreters - selector', () => { workspace = TypeMoq.Mock.ofType(); fileSystem = TypeMoq.Mock.ofType(); fileSystem.setup(x => x.arePathsSame(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns((a: string, b: string) => a === b); - fileSystem.setup(x => x.getRealPath(TypeMoq.It.isAnyString())).returns((a: string) => new Promise(resolve => resolve(a))); configurationService.setup(x => x.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object); comparer.setup(c => c.compare(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => 0);