提交 66f5e929 编写于 作者: B Benjamin Pasero

path lib usage 💄

上级 08e29d24
......@@ -725,16 +725,16 @@ export class FileService extends Disposable implements IFileService {
// Check if source is equal or parent to target (requires providers to be the same)
if (sourceProvider === targetProvider) {
const { extUri, isPathCaseSensitive } = this.getExtUri(sourceProvider);
const { providerExtUri, isPathCaseSensitive } = this.getExtUri(sourceProvider);
if (!isPathCaseSensitive) {
isSameResourceWithDifferentPathCase = extUri.isEqual(source, target);
isSameResourceWithDifferentPathCase = providerExtUri.isEqual(source, target);
}
if (isSameResourceWithDifferentPathCase && mode === 'copy') {
throw new Error(localize('unableToMoveCopyError1', "Unable to copy when source '{0}' is same as target '{1}' with different path case on a case insensitive file system", this.resourceForError(source), this.resourceForError(target)));
}
if (!isSameResourceWithDifferentPathCase && extUri.isEqualOrParent(target, source)) {
if (!isSameResourceWithDifferentPathCase && providerExtUri.isEqualOrParent(target, source)) {
throw new Error(localize('unableToMoveCopyError2', "Unable to move/copy when source '{0}' is parent of target '{1}'.", this.resourceForError(source), this.resourceForError(target)));
}
}
......@@ -751,8 +751,8 @@ export class FileService extends Disposable implements IFileService {
// Special case: if the target is a parent of the source, we cannot delete
// it as it would delete the source as well. In this case we have to throw
if (sourceProvider === targetProvider) {
const { extUri } = this.getExtUri(sourceProvider);
if (extUri.isEqualOrParent(source, target)) {
const { providerExtUri } = this.getExtUri(sourceProvider);
if (providerExtUri.isEqualOrParent(source, target)) {
throw new Error(localize('unableToMoveCopyError4', "Unable to move/copy '{0}' into '{1}' since a file would replace the folder it is contained in.", this.resourceForError(source), this.resourceForError(target)));
}
}
......@@ -761,11 +761,11 @@ export class FileService extends Disposable implements IFileService {
return { exists, isSameResourceWithDifferentPathCase };
}
private getExtUri(provider: IFileSystemProvider): { extUri: IExtUri, isPathCaseSensitive: boolean } {
private getExtUri(provider: IFileSystemProvider): { providerExtUri: IExtUri, isPathCaseSensitive: boolean } {
const isPathCaseSensitive = this.isPathCaseSensitive(provider);
return {
extUri: isPathCaseSensitive ? extUri : extUriIgnorePathCase,
providerExtUri: isPathCaseSensitive ? extUri : extUriIgnorePathCase,
isPathCaseSensitive
};
}
......@@ -791,8 +791,8 @@ export class FileService extends Disposable implements IFileService {
const directoriesToCreate: string[] = [];
// mkdir until we reach root
const { extUri } = this.getExtUri(provider);
while (!extUri.isEqual(directory, dirname(directory))) {
const { providerExtUri } = this.getExtUri(provider);
while (!providerExtUri.isEqual(directory, dirname(directory))) {
try {
const stat = await provider.stat(directory);
if ((stat.type & FileType.Directory) === 0) {
......@@ -940,12 +940,12 @@ export class FileService extends Disposable implements IFileService {
}
private toWatchKey(provider: IFileSystemProvider, resource: URI, options: IWatchOptions): string {
const { extUri } = this.getExtUri(provider);
const { providerExtUri } = this.getExtUri(provider);
return [
extUri.getComparisonKey(resource), // lowercase path if the provider is case insensitive
String(options.recursive), // use recursive: true | false as part of the key
options.excludes.join() // use excludes as part of the key
providerExtUri.getComparisonKey(resource), // lowercase path if the provider is case insensitive
String(options.recursive), // use recursive: true | false as part of the key
options.excludes.join() // use excludes as part of the key
].join();
}
......@@ -963,8 +963,8 @@ export class FileService extends Disposable implements IFileService {
private readonly writeQueues: Map<string, Queue<void>> = new Map();
private ensureWriteQueue(provider: IFileSystemProvider, resource: URI): Queue<void> {
const { extUri } = this.getExtUri(provider);
const queueKey = extUri.getComparisonKey(resource);
const { providerExtUri } = this.getExtUri(provider);
const queueKey = providerExtUri.getComparisonKey(resource);
// ensure to never write to the same resource without finishing
// the one write. this ensures a write finishes consistently
......
......@@ -3,12 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nsfw from 'vscode-nsfw';
import * as glob from 'vs/base/common/glob';
import * as extpath from 'vs/base/common/extpath';
import * as path from 'vs/base/common/path';
import * as platform from 'vs/base/common/platform';
import { join } from 'vs/base/common/path';
import { isMacintosh } from 'vs/base/common/platform';
import { isEqualOrParent } from 'vs/base/common/extpath';
import { IDiskFileChange, normalizeFileChanges, ILogMessage } from 'vs/platform/files/node/watcher/watcher';
import * as nsfw from 'vscode-nsfw';
import { IWatcherService, IWatcherRequest } from 'vs/platform/files/node/watcher/nsfw/watcher';
import { ThrottledDelayer } from 'vs/base/common/async';
import { FileChangeType } from 'vs/platform/files/common/files';
......@@ -111,7 +111,7 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
// We have to detect this case and massage the events to correct this.
let realBasePathDiffers = false;
let realBasePathLength = request.path.length;
if (platform.isMacintosh) {
if (isMacintosh) {
try {
// First check for symbolic link
......@@ -141,7 +141,7 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
for (const e of events) {
// Logging
if (this.verboseLogging) {
const logPath = e.action === nsfw.actions.RENAMED ? path.join(e.directory, e.oldFile || '') + ' -> ' + e.newFile : path.join(e.directory, e.file || '');
const logPath = e.action === nsfw.actions.RENAMED ? join(e.directory, e.oldFile || '') + ' -> ' + e.newFile : join(e.directory, e.file || '');
this.log(`${e.action === nsfw.actions.CREATED ? '[CREATED]' : e.action === nsfw.actions.DELETED ? '[DELETED]' : e.action === nsfw.actions.MODIFIED ? '[CHANGED]' : '[RENAMED]'} ${logPath}`);
}
......@@ -149,20 +149,20 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
let absolutePath: string;
if (e.action === nsfw.actions.RENAMED) {
// Rename fires when a file's name changes within a single directory
absolutePath = path.join(e.directory, e.oldFile || '');
absolutePath = join(e.directory, e.oldFile || '');
if (!this.isPathIgnored(absolutePath, this.pathWatchers[request.path].ignored)) {
undeliveredFileEvents.push({ type: FileChangeType.DELETED, path: absolutePath });
} else if (this.verboseLogging) {
this.log(` >> ignored ${absolutePath}`);
}
absolutePath = path.join(e.newDirectory || e.directory, e.newFile || '');
absolutePath = join(e.newDirectory || e.directory, e.newFile || '');
if (!this.isPathIgnored(absolutePath, this.pathWatchers[request.path].ignored)) {
undeliveredFileEvents.push({ type: FileChangeType.ADDED, path: absolutePath });
} else if (this.verboseLogging) {
this.log(` >> ignored ${absolutePath}`);
}
} else {
absolutePath = path.join(e.directory, e.file || '');
absolutePath = join(e.directory, e.file || '');
if (!this.isPathIgnored(absolutePath, this.pathWatchers[request.path].ignored)) {
undeliveredFileEvents.push({
type: nsfwActionToRawChangeType[e.action],
......@@ -179,7 +179,7 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
const events = undeliveredFileEvents;
undeliveredFileEvents = [];
if (platform.isMacintosh) {
if (isMacintosh) {
events.forEach(e => {
// Mac uses NFD unicode form on disk, but we want NFC
......@@ -230,7 +230,7 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
// Normalizes a set of root paths by removing any root paths that are
// sub-paths of other roots.
return roots.filter(r => roots.every(other => {
return !(r.path.length > other.path.length && extpath.isEqualOrParent(r.path, other.path));
return !(r.path.length > other.path.length && isEqualOrParent(r.path, other.path));
}));
}
......
......@@ -6,9 +6,8 @@
import * as chokidar from 'chokidar';
import * as fs from 'fs';
import * as gracefulFs from 'graceful-fs';
gracefulFs.gracefulify(fs);
import * as extpath from 'vs/base/common/extpath';
import * as glob from 'vs/base/common/glob';
import { isEqualOrParent } from 'vs/base/common/extpath';
import { FileChangeType } from 'vs/platform/files/common/files';
import { ThrottledDelayer } from 'vs/base/common/async';
import { normalizeNFC } from 'vs/base/common/normalization';
......@@ -20,6 +19,8 @@ import { Emitter, Event } from 'vs/base/common/event';
import { equals } from 'vs/base/common/arrays';
import { Disposable } from 'vs/base/common/lifecycle';
gracefulFs.gracefulify(fs); // enable gracefulFs
process.noAsar = true; // disable ASAR support in watcher process
interface IWatcher {
......@@ -311,7 +312,7 @@ function isIgnored(path: string, requests: ExtendedWatcherRequest[]): boolean {
return false;
}
if (extpath.isEqualOrParent(path, request.path)) {
if (isEqualOrParent(path, request.path)) {
if (!request.parsedPattern) {
if (request.excludes && request.excludes.length > 0) {
const pattern = `{${request.excludes.join(',')}}`;
......@@ -343,7 +344,7 @@ export function normalizeRoots(requests: IWatcherRequest[]): { [basePath: string
for (const request of requests) {
const basePath = request.path;
const ignored = (request.excludes || []).sort();
if (prevRequest && (extpath.isEqualOrParent(basePath, prevRequest.path))) {
if (prevRequest && (isEqualOrParent(basePath, prevRequest.path))) {
if (!isEqualIgnore(ignored, prevRequest.excludes)) {
result[prevRequest.path].push({ path: basePath, excludes: ignored });
}
......
......@@ -12,7 +12,7 @@ import { isLinux } from 'vs/base/common/platform';
import { Event, Emitter } from 'vs/base/common/event';
import { ILogService } from 'vs/platform/log/common/log';
import { createHash } from 'crypto';
import * as json from 'vs/base/common/json';
import { parse } from 'vs/base/common/json';
import { toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
......@@ -66,7 +66,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
declare readonly _serviceBrand: undefined;
private readonly untitledWorkspacesHome: URI; // local URI that contains all untitled workspaces
private readonly untitledWorkspacesHome = this.environmentService.untitledWorkspacesHome; // local URI that contains all untitled workspaces
private readonly _onUntitledWorkspaceDeleted = this._register(new Emitter<IWorkspaceIdentifier>());
readonly onUntitledWorkspaceDeleted: Event<IWorkspaceIdentifier> = this._onUntitledWorkspaceDeleted.event;
......@@ -81,8 +81,6 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
@IDialogMainService private readonly dialogMainService: IDialogMainService
) {
super();
this.untitledWorkspacesHome = environmentService.untitledWorkspacesHome;
}
resolveLocalWorkspaceSync(uri: URI): IResolvedWorkspace | null {
......@@ -127,7 +125,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
private doParseStoredWorkspace(path: URI, contents: string): IStoredWorkspace {
// Parse workspace file
let storedWorkspace: IStoredWorkspace = json.parse(contents); // use fault tolerant parser
const storedWorkspace: IStoredWorkspace = parse(contents); // use fault tolerant parser
// Filter out folders which do not have a path or uri set
if (storedWorkspace && Array.isArray(storedWorkspace.folders)) {
......@@ -226,7 +224,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
}
getUntitledWorkspacesSync(): IUntitledWorkspaceInfo[] {
let untitledWorkspaces: IUntitledWorkspaceInfo[] = [];
const untitledWorkspaces: IUntitledWorkspaceInfo[] = [];
try {
const untitledWorkspacePaths = readdirSync(this.untitledWorkspacesHome.fsPath).map(folder => joinPath(this.untitledWorkspacesHome, folder, UNTITLED_WORKSPACE_NAME));
for (const untitledWorkspacePath of untitledWorkspacePaths) {
......@@ -243,6 +241,7 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
this.logService.warn(`Unable to read folders in ${this.untitledWorkspacesHome} (${error}).`);
}
}
return untitledWorkspaces;
}
......
......@@ -9,7 +9,7 @@ import { OperatingSystem } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { TerminalLink, OPEN_FILE_LABEL, FOLDER_IN_WORKSPACE_LABEL, FOLDER_NOT_IN_WORKSPACE_LABEL } from 'vs/workbench/contrib/terminal/browser/links/terminalLink';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { isEqualOrParent } from 'vs/base/common/resources';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IHostService } from 'vs/workbench/services/host/browser/host';
......@@ -62,7 +62,8 @@ export class TerminalValidatedLocalLinkProvider extends TerminalBaseLinkProvider
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@ICommandService private readonly _commandService: ICommandService,
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService,
@IHostService private readonly _hostService: IHostService
@IHostService private readonly _hostService: IHostService,
@IUriIdentityService private readonly _uriIdentityService: IUriIdentityService
) {
super();
}
......@@ -183,7 +184,7 @@ export class TerminalValidatedLocalLinkProvider extends TerminalBaseLinkProvider
private _isDirectoryInsideWorkspace(uri: URI) {
const folders = this._workspaceContextService.getWorkspace().folders;
for (let i = 0; i < folders.length; i++) {
if (isEqualOrParent(uri, folders[i].uri)) {
if (this._uriIdentityService.extUri.isEqualOrParent(uri, folders[i].uri)) {
return true;
}
}
......
......@@ -11,7 +11,7 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn
import { Registry } from 'vs/platform/registry/common/platform';
import { ResourceMap } from 'vs/base/common/map';
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
import { IFileService, FileOperationEvent, FileOperation, FileChangesEvent, FileChangeType, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { IFileService, FileOperationEvent, FileOperation, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
import { Event, Emitter } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
......@@ -251,8 +251,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
if (this.uriIdentityService.extUri.isEqual(source, resource)) {
targetResource = target; // file got moved
} else {
const ignoreCase = !this.fileService.hasCapability(resource, FileSystemProviderCapabilities.PathCaseSensitive);
const index = indexOfPath(resource.path, source.path, ignoreCase);
const index = indexOfPath(resource.path, source.path, this.uriIdentityService.extUri.ignorePathCasing(resource));
targetResource = joinPath(target, resource.path.substr(index + source.path.length + 1)); // parent folder got moved
}
......
......@@ -221,6 +221,7 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
}
// Allow to save the workspace of the current window
// if we have an identical match on the path
if (isEqual(workspaceIdentifier.configPath, path)) {
return this.saveWorkspace(workspaceIdentifier);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册