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

This commit is contained in:
Benjamin Pasero
2018-09-04 14:05:38 +02:00
parent 8c4a4c10f7
commit 69e7247efd
2 changed files with 15 additions and 24 deletions
+7 -13
View File
@@ -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;