提交 98953dd9 编写于 作者: M Martin Aeschlimann

rename resources.fsPath to resources.originalFSPath

上级 833fc7aa
......@@ -33,7 +33,7 @@ export function basenameOrAuthority(resource: URI): string {
export function isEqualOrParent(base: URI, parentCandidate: URI, ignoreCase = hasToIgnoreCase(base)): boolean {
if (base.scheme === parentCandidate.scheme) {
if (base.scheme === Schemas.file) {
return extpath.isEqualOrParent(fsPath(base), fsPath(parentCandidate), ignoreCase);
return extpath.isEqualOrParent(originalFSPath(base), originalFSPath(parentCandidate), ignoreCase);
}
if (isEqualAuthority(base.authority, parentCandidate.authority)) {
return extpath.isEqualOrParent(base.path, parentCandidate.path, ignoreCase, '/');
......@@ -82,7 +82,7 @@ export function dirname(resource: URI): URI {
return resource;
}
if (resource.scheme === Schemas.file) {
return URI.file(paths.dirname(fsPath(resource)));
return URI.file(paths.dirname(originalFSPath(resource)));
}
let dirname = paths.posix.dirname(resource.path);
if (resource.authority && dirname.length && dirname.charCodeAt(0) !== CharCode.Slash) {
......@@ -104,7 +104,7 @@ export function dirname(resource: URI): URI {
export function joinPath(resource: URI, ...pathFragment: string[]): URI {
let joinedPath: string;
if (resource.scheme === Schemas.file) {
joinedPath = URI.file(paths.join(fsPath(resource), ...pathFragment)).path;
joinedPath = URI.file(paths.join(originalFSPath(resource), ...pathFragment)).path;
} else {
joinedPath = paths.posix.join(resource.path || '/', ...pathFragment);
}
......@@ -125,7 +125,7 @@ export function normalizePath(resource: URI): URI {
}
let normalizedPath: string;
if (resource.scheme === Schemas.file) {
normalizedPath = URI.file(paths.normalize(fsPath(resource))).path;
normalizedPath = URI.file(paths.normalize(originalFSPath(resource))).path;
} else {
normalizedPath = paths.posix.normalize(resource.path);
}
......@@ -138,7 +138,7 @@ export function normalizePath(resource: URI): URI {
* Returns the fsPath of an URI where the drive letter is not normalized.
* See #56403.
*/
export function fsPath(uri: URI): string {
export function originalFSPath(uri: URI): string {
let value: string;
const uriPath = uri.path;
if (uri.authority && uriPath.length > 1 && uri.scheme === 'file') {
......@@ -173,7 +173,7 @@ export function isAbsolutePath(resource: URI): boolean {
*/
export function hasTrailingPathSeparator(resource: URI): boolean {
if (resource.scheme === Schemas.file) {
const fsp = fsPath(resource);
const fsp = originalFSPath(resource);
return fsp.length > extpath.getRoot(fsp).length && fsp[fsp.length - 1] === paths.sep;
} else {
let p = resource.path;
......
......@@ -34,7 +34,7 @@ import { normalizeNFC } from 'vs/base/common/normalization';
import { URI } from 'vs/base/common/uri';
import { Queue, timeout } from 'vs/base/common/async';
import { exists } from 'vs/base/node/pfs';
import { getComparisonKey, isEqual, normalizePath, basename as resourcesBasename, fsPath, hasTrailingPathSeparator, removeTrailingPathSeparator } from 'vs/base/common/resources';
import { getComparisonKey, isEqual, normalizePath, basename as resourcesBasename, originalFSPath, hasTrailingPathSeparator, removeTrailingPathSeparator } from 'vs/base/common/resources';
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
import { restoreWindowsState, WindowsStateStorageData, getWindowsStateStoreData } from 'vs/code/electron-main/windowsStateStorage';
......@@ -1150,7 +1150,7 @@ export class WindowsManager implements IWindowsMainService {
}
} else {
if (workspaceToOpen.configPath.scheme === Schemas.file) {
cliArgs = [fsPath(workspaceToOpen.configPath)];
cliArgs = [originalFSPath(workspaceToOpen.configPath)];
} else {
fileUris = [workspaceToOpen.configPath.toString()];
}
......
......@@ -16,7 +16,7 @@ import { IWorkspaceIdentifier, IWorkspacesMainService, ISingleFolderWorkspaceIde
import { IHistoryMainService, IRecentlyOpened } from 'vs/platform/history/common/history';
import { isEqual } from 'vs/base/common/extpath';
import { RunOnceScheduler } from 'vs/base/common/async';
import { getComparisonKey, isEqual as areResourcesEqual, dirname, fsPath } from 'vs/base/common/resources';
import { getComparisonKey, isEqual as areResourcesEqual, dirname, originalFSPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
......@@ -169,12 +169,12 @@ export class HistoryMainService implements IHistoryMainService {
const workspace = mru.workspaces[i];
if (isSingleFolderWorkspaceIdentifier(workspace)) {
if (workspace.scheme === Schemas.file) {
app.addRecentDocument(fsPath(workspace));
app.addRecentDocument(originalFSPath(workspace));
entries++;
}
} else {
if (workspace.configPath.scheme === Schemas.file) {
app.addRecentDocument(fsPath(workspace.configPath));
app.addRecentDocument(originalFSPath(workspace.configPath));
entries++;
}
}
......@@ -185,7 +185,7 @@ export class HistoryMainService implements IHistoryMainService {
for (let i = 0; i < mru.files.length && entries < HistoryMainService.MAX_MACOS_DOCK_RECENT_FILES; i++) {
const file = mru.files[i];
if (file.scheme === Schemas.file) {
app.addRecentDocument(fsPath(file));
app.addRecentDocument(originalFSPath(file));
entries++;
}
}
......
......@@ -12,7 +12,7 @@ import { isEqualOrParent, normalizeWithSlashes } from 'vs/base/common/extpath';
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
import { isAbsolute, relative, posix, resolve, extname } from 'vs/base/common/path';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { fsPath, dirname } from 'vs/base/common/resources';
import { originalFSPath, dirname } from 'vs/base/common/resources';
import { Schemas } from 'vs/base/common/network';
import * as jsonEdit from 'vs/base/common/jsonEdit';
import * as json from 'vs/base/common/json';
......@@ -166,7 +166,7 @@ const SLASH = '/';
export function massageFolderPathForWorkspace(absoluteFolderPath: string, targetConfigFolderURI: URI, existingFolders: IStoredWorkspaceFolder[]): string {
if (targetConfigFolderURI.scheme === Schemas.file) {
const targetFolderPath = fsPath(targetConfigFolderURI);
const targetFolderPath = originalFSPath(targetConfigFolderURI);
// Convert path to relative path if the target config folder
// is a parent of the path.
if (isEqualOrParent(absoluteFolderPath, targetFolderPath, !isLinux)) {
......@@ -213,7 +213,7 @@ export function rewriteWorkspaceFileForNewLocation(rawWorkspaceContents: string,
if (isRawFileWorkspaceFolder(folder)) {
if (sourceConfigFolder.scheme === Schemas.file) {
if (!isAbsolute(folder.path)) {
folder.path = resolve(fsPath(sourceConfigFolder), folder.path); // relative paths get resolved against the workspace location
folder.path = resolve(originalFSPath(sourceConfigFolder), folder.path); // relative paths get resolved against the workspace location
}
folder.path = massageFolderPathForWorkspace(folder.path, targetConfigFolder, storedWorkspace.folders);
}
......
......@@ -19,7 +19,7 @@ import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
import { Disposable } from 'vs/base/common/lifecycle';
import { fsPath, dirname as resourcesDirname, isEqualOrParent, joinPath } from 'vs/base/common/resources';
import { originalFSPath, dirname as resourcesDirname, isEqualOrParent, joinPath } from 'vs/base/common/resources';
export interface IStoredWorkspace {
folders: IStoredWorkspaceFolder[];
......@@ -142,7 +142,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
// File URI
if (folderResource.scheme === Schemas.file) {
storedWorkspace = { path: massageFolderPathForWorkspace(fsPath(folderResource), untitledWorkspaceConfigFolder, []) };
storedWorkspace = { path: massageFolderPathForWorkspace(originalFSPath(folderResource), untitledWorkspaceConfigFolder, []) };
}
// Any URI
......@@ -165,7 +165,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
}
getWorkspaceId(configPath: URI): string {
let workspaceConfigPath = configPath.scheme === Schemas.file ? fsPath(configPath) : configPath.toString();
let workspaceConfigPath = configPath.scheme === Schemas.file ? originalFSPath(configPath) : configPath.toString();
if (!isLinux) {
workspaceConfigPath = workspaceConfigPath.toLowerCase(); // sanitize for platform file system
}
......@@ -190,7 +190,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
throw new Error('Only local workspaces can be saved with this API. Use WorkspaceEditingService.saveWorkspaceAs on the renderer instead.');
}
const configPath = fsPath(workspace.configPath);
const configPath = originalFSPath(workspace.configPath);
// Return early if target is same as source
if (isEqual(configPath, targetConfigPath, !isLinux)) {
......@@ -221,7 +221,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
}
private doDeleteUntitledWorkspaceSync(workspace: IWorkspaceIdentifier): void {
const configPath = fsPath(workspace.configPath);
const configPath = originalFSPath(workspace.configPath);
try {
// Delete Workspace
delSync(dirname(configPath));
......
......@@ -64,6 +64,7 @@ import { ProxyIdentifier } from 'vs/workbench/services/extensions/node/proxyIden
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/node/extensionDescriptionRegistry';
import * as vscode from 'vscode';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { originalFSPath } from 'vs/base/common/resources';
export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, workspaceProvider: ExtHostWorkspaceProvider, configProvider: ExtHostConfigProvider): typeof vscode;
......@@ -841,18 +842,6 @@ export function createApiFactory(
};
}
/**
* Returns the original fs path (using the original casing for the drive letter)
*/
export function originalFSPath(uri: URI): string {
const result = uri.fsPath;
if (/^[a-zA-Z]:/.test(result) && uri.path.charAt(1).toLowerCase() === result.charAt(0)) {
// Restore original drive letter casing
return uri.path.charAt(1) + result.substr(1);
}
return result;
}
class Extension<T> implements vscode.Extension<T> {
private _extensionService: ExtHostExtensionService;
......
......@@ -36,7 +36,7 @@ import { Uri } from 'vscode';
import { createHash } from 'crypto';
import { Emitter, Event } from 'vs/base/common/event';
import { Schemas } from 'vs/base/common/network';
import { fsPath } from 'vs/base/common/resources';
import { originalFSPath } from 'vs/base/common/resources';
import { isLinux } from 'vs/base/common/platform';
import { IWorkspaceIdentifier } from 'vs/workbench/services/configuration/node/configuration';
......@@ -1246,7 +1246,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
});
function getWorkspaceId(configPath: URI): string {
let workspaceConfigPath = configPath.scheme === Schemas.file ? fsPath(configPath) : configPath.toString();
let workspaceConfigPath = configPath.scheme === Schemas.file ? originalFSPath(configPath) : configPath.toString();
if (!isLinux) {
workspaceConfigPath = workspaceConfigPath.toLowerCase(); // sanitize for platform file system
}
......
......@@ -11,7 +11,7 @@ import * as errors from 'vs/base/common/errors';
import { Schemas } from 'vs/base/common/network';
import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import { fsPath } from 'vs/base/common/resources';
import { originalFSPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import * as pfs from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
......@@ -297,7 +297,7 @@ export class CachedExtensionScanner {
let developedExtensions: Promise<IExtensionDescription[]> = Promise.resolve([]);
if (environmentService.isExtensionDevelopment && environmentService.extensionDevelopmentLocationURI && environmentService.extensionDevelopmentLocationURI.scheme === Schemas.file) {
developedExtensions = ExtensionScanner.scanOneOrMultipleExtensions(
new ExtensionScannerInput(version, commit, locale, devMode, fsPath(environmentService.extensionDevelopmentLocationURI), false, true, translations), log
new ExtensionScannerInput(version, commit, locale, devMode, originalFSPath(environmentService.extensionDevelopmentLocationURI), false, true, translations), log
);
}
......
......@@ -5,14 +5,17 @@
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { originalFSPath } from 'vs/workbench/api/node/extHost.api.impl';
import { originalFSPath } from 'vs/base/common/resources';
import { isWindows } from 'vs/base/common/platform';
suite('ExtHost API', function () {
test('issue #51387: originalFSPath', function () {
assert.equal(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.equal(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
if (isWindows) {
assert.equal(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.equal(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
}
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册