From 2baecc900c170b5c38e2a7d022098745bf4ee034 Mon Sep 17 00:00:00 2001 From: Lital Avigad Date: Tue, 1 Dec 2020 15:43:34 +0200 Subject: [PATCH] Paste file/folder to other folder that already contain file/folder with the same name Signed-off-by: Lital Avigad --- packages/filesystem/src/browser/file-service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/filesystem/src/browser/file-service.ts b/packages/filesystem/src/browser/file-service.ts index 1120aaaa3e6fc..89493b5e5774e 100644 --- a/packages/filesystem/src/browser/file-service.ts +++ b/packages/filesystem/src/browser/file-service.ts @@ -66,6 +66,7 @@ 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 { @@ -1116,6 +1117,13 @@ 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 }); @@ -1231,11 +1239,6 @@ export class FileService { const exists = await this.exists(target); if (exists && !isSameResourceWithDifferentPathCase) { - // Bail out if target exists and we are not about to overwrite - if (!overwrite) { - throw new FileOperationError(`Unable to move/copy '${this.resourceForError(source)}' because target '${this.resourceForError(target)}' already exists at destination.`, FileOperationResult.FILE_MOVE_CONFLICT); - } - // 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) {