diff --git a/src/vs/code/node/paths.ts b/src/vs/code/node/paths.ts index d54353ff72ee4e7b5142ef8c61073ab49e808890..5a74d360ea01922e98f4c993afc6af5596bbe730 100644 --- a/src/vs/code/node/paths.ts +++ b/src/vs/code/node/paths.ts @@ -12,16 +12,16 @@ import * as paths from 'vs/base/common/paths'; import * as platform from 'vs/base/common/platform'; import * as types from 'vs/base/common/types'; import { ParsedArgs } from 'vs/platform/environment/common/environment'; -import { realpathSync } from 'vs/base/node/extfs'; export function validatePaths(args: ParsedArgs): ParsedArgs { + // Track URLs if they're going to be used if (args['open-url']) { args._urls = args._; args._ = []; } - // Realpath/normalize paths and watch out for goto line mode + // Normalize paths and watch out for goto line mode const paths = doValidatePaths(args._, args.goto); // Update environment @@ -46,26 +46,20 @@ function doValidatePaths(args: string[], gotoLineMode?: boolean): string[] { pathCandidate = preparePath(cwd, pathCandidate); } - let realPath: string; - try { - realPath = realpathSync(pathCandidate); - } catch (error) { - // in case of an error, assume the user wants to create this file - // if the path is relative, we join it to the cwd - realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate)); - } + const absolutePath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate)); - const basename = path.basename(realPath); + const basename = path.basename(absolutePath); if (basename /* can be empty if code is opened on root */ && !paths.isValidBasename(basename)) { return null; // do not allow invalid file names } if (gotoLineMode) { - parsedPath.path = realPath; + parsedPath.path = absolutePath; + return toPath(parsedPath); } - return realPath; + return absolutePath; }); const caseInsensitive = platform.isWindows || platform.isMacintosh; diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 93a010516dca3cef30d36443a07ac5f32a5fccea..2344c7994b4131db24ebbcd97c2a520476508ff9 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -21,7 +21,8 @@ import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { realpath } from 'vs/base/node/pfs'; +import { stat } from 'vs/base/node/pfs'; +import { normalize, join, isAbsolute } from 'path'; import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; import * as gracefulFs from 'graceful-fs'; import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService'; @@ -147,18 +148,19 @@ function validateFolderUri(folderUri: ISingleFolderWorkspaceIdentifier, verbose: return TPromise.as(folderUri); } - // Otherwise: use realpath to resolve symbolic links to the truth - return realpath(folderUri.fsPath).then(realFolderPath => { + // Ensure absolute existing folder path + let absoluteFolderPath = normalize(isAbsolute(folderUri.fsPath) ? folderUri.fsPath : join(process.env['VSCODE_CWD'] || process.cwd(), folderUri.fsPath)); + return stat(absoluteFolderPath).then(stat => { // For some weird reason, node adds a trailing slash to UNC paths // we never ever want trailing slashes as our workspace path unless // someone opens root ("/"). // See also https://github.com/nodejs/io.js/issues/1765 - if (paths.isUNC(realFolderPath) && strings.endsWith(realFolderPath, paths.nativeSep)) { - realFolderPath = strings.rtrim(realFolderPath, paths.nativeSep); + if (paths.isUNC(absoluteFolderPath) && strings.endsWith(absoluteFolderPath, paths.nativeSep)) { + absoluteFolderPath = strings.rtrim(absoluteFolderPath, paths.nativeSep); } - return uri.file(realFolderPath); + return uri.file(absoluteFolderPath); }, error => { if (verbose) { errors.onUnexpectedError(error); @@ -166,11 +168,6 @@ function validateFolderUri(folderUri: ISingleFolderWorkspaceIdentifier, verbose: // Treat any error case as empty workbench case (no folder path) return null; - - }).then(realFolderUriOrNull => { - - // Update config with real path if we have one - return realFolderUriOrNull; }); }