diff --git a/packages/filesystem/src/browser/file-service.ts b/packages/filesystem/src/browser/file-service.ts index 89493b5e5774e..0e51c04a0beb2 100644 --- a/packages/filesystem/src/browser/file-service.ts +++ b/packages/filesystem/src/browser/file-service.ts @@ -66,7 +66,6 @@ import { EncodingService, ResourceEncoding, DecodeStreamResult } from '@theia/co import { Mutable } from '@theia/core/lib/common/types'; import { readFileIntoStream } from '../common/io'; import { FileSystemWatcherErrorHandler } from './filesystem-watcher-error-handler'; -import { FileSystemUtils } from '../common/filesystem-utils'; export interface FileOperationParticipant { @@ -1117,13 +1116,6 @@ export class FileService { // validation const { exists, isSameResourceWithDifferentPathCase } = await this.doValidateMoveCopy(sourceProvider, source, targetProvider, target, mode, overwrite); - // if target exists get valid target - if (exists && !overwrite) { - const parent = await this.resolve(target.parent); - const name = target.path.name + '_copy'; - target = FileSystemUtils.generateUniqueResourceURI(target.parent, parent, name, target.path.ext); - } - // delete as needed (unless target is same resource with different path case) if (exists && !isSameResourceWithDifferentPathCase && overwrite) { await this.delete(target, { recursive: true }); diff --git a/packages/filesystem/src/browser/file-tree/file-tree-model.ts b/packages/filesystem/src/browser/file-tree/file-tree-model.ts index 1f8440e41157d..5b631eb037bdd 100644 --- a/packages/filesystem/src/browser/file-tree/file-tree-model.ts +++ b/packages/filesystem/src/browser/file-tree/file-tree-model.ts @@ -24,6 +24,7 @@ import { FileService } from '../file-service'; import { FileOperationError, FileOperationResult, FileChangesEvent, FileChangeType, FileChange, FileOperation, FileOperationEvent } from '../../common/files'; import { MessageService } from '@theia/core/lib/common/message-service'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; +import { FileSystemUtils } from '../../common'; @injectable() export class FileTreeModel extends TreeModelImpl implements LocationService { @@ -148,8 +149,13 @@ export class FileTreeModel extends TreeModelImpl implements LocationService { } async copy(source: URI, target: Readonly): Promise { - const targetUri = target.uri.resolve(source.path.base); + let targetUri = target.uri.resolve(source.path.base); try { + if (source.path.toString() === target.uri.path.toString()) { + const parent = await this.fileService.resolve(source.parent); + const name = source.path.name + '_copy'; + targetUri = FileSystemUtils.generateUniqueResourceURI(source.parent, parent, name, source.path.ext); + } await this.fileService.copy(source, targetUri); } catch (e) { this.messageService.error(e.message);