Skip to content

Commit 69e7247

Browse files
author
Benjamin Pasero
committed
stop fs.realpath when opening so that symlinks are left intact (fixes microsoft#18837)
1 parent 8c4a4c1 commit 69e7247

2 files changed

Lines changed: 15 additions & 24 deletions

File tree

src/vs/code/node/paths.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import * as paths from 'vs/base/common/paths';
1212
import * as platform from 'vs/base/common/platform';
1313
import * as types from 'vs/base/common/types';
1414
import { ParsedArgs } from 'vs/platform/environment/common/environment';
15-
import { realpathSync } from 'vs/base/node/extfs';
1615

1716
export function validatePaths(args: ParsedArgs): ParsedArgs {
17+
1818
// Track URLs if they're going to be used
1919
if (args['open-url']) {
2020
args._urls = args._;
2121
args._ = [];
2222
}
2323

24-
// Realpath/normalize paths and watch out for goto line mode
24+
// Normalize paths and watch out for goto line mode
2525
const paths = doValidatePaths(args._, args.goto);
2626

2727
// Update environment
@@ -46,26 +46,20 @@ function doValidatePaths(args: string[], gotoLineMode?: boolean): string[] {
4646
pathCandidate = preparePath(cwd, pathCandidate);
4747
}
4848

49-
let realPath: string;
50-
try {
51-
realPath = realpathSync(pathCandidate);
52-
} catch (error) {
53-
// in case of an error, assume the user wants to create this file
54-
// if the path is relative, we join it to the cwd
55-
realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate));
56-
}
49+
const absolutePath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate));
5750

58-
const basename = path.basename(realPath);
51+
const basename = path.basename(absolutePath);
5952
if (basename /* can be empty if code is opened on root */ && !paths.isValidBasename(basename)) {
6053
return null; // do not allow invalid file names
6154
}
6255

6356
if (gotoLineMode) {
64-
parsedPath.path = realPath;
57+
parsedPath.path = absolutePath;
58+
6559
return toPath(parsedPath);
6660
}
6761

68-
return realPath;
62+
return absolutePath;
6963
});
7064

7165
const caseInsensitive = platform.isWindows || platform.isMacintosh;

src/vs/workbench/electron-browser/main.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { IWorkspaceContextService, Workspace, WorkbenchState } from 'vs/platform
2121
import { WorkspaceService } from 'vs/workbench/services/configuration/node/configurationService';
2222
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
2323
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
24-
import { realpath } from 'vs/base/node/pfs';
24+
import { stat } from 'vs/base/node/pfs';
25+
import { normalize, join, isAbsolute } from 'path';
2526
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
2627
import * as gracefulFs from 'graceful-fs';
2728
import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
@@ -147,30 +148,26 @@ function validateFolderUri(folderUri: ISingleFolderWorkspaceIdentifier, verbose:
147148
return TPromise.as(folderUri);
148149
}
149150

150-
// Otherwise: use realpath to resolve symbolic links to the truth
151-
return realpath(folderUri.fsPath).then(realFolderPath => {
151+
// Ensure absolute existing folder path
152+
let absoluteFolderPath = normalize(isAbsolute(folderUri.fsPath) ? folderUri.fsPath : join(process.env['VSCODE_CWD'] || process.cwd(), folderUri.fsPath));
153+
return stat(absoluteFolderPath).then(stat => {
152154

153155
// For some weird reason, node adds a trailing slash to UNC paths
154156
// we never ever want trailing slashes as our workspace path unless
155157
// someone opens root ("/").
156158
// See also https://github.com/nodejs/io.js/issues/1765
157-
if (paths.isUNC(realFolderPath) && strings.endsWith(realFolderPath, paths.nativeSep)) {
158-
realFolderPath = strings.rtrim(realFolderPath, paths.nativeSep);
159+
if (paths.isUNC(absoluteFolderPath) && strings.endsWith(absoluteFolderPath, paths.nativeSep)) {
160+
absoluteFolderPath = strings.rtrim(absoluteFolderPath, paths.nativeSep);
159161
}
160162

161-
return uri.file(realFolderPath);
163+
return uri.file(absoluteFolderPath);
162164
}, error => {
163165
if (verbose) {
164166
errors.onUnexpectedError(error);
165167
}
166168

167169
// Treat any error case as empty workbench case (no folder path)
168170
return null;
169-
170-
}).then(realFolderUriOrNull => {
171-
172-
// Update config with real path if we have one
173-
return realFolderUriOrNull;
174171
});
175172
}
176173

0 commit comments

Comments
 (0)