提交 69e7247e 编写于 作者: B Benjamin Pasero

stop fs.realpath when opening so that symlinks are left intact (fixes #18837)

上级 8c4a4c10
......@@ -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;
......
......@@ -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;
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册