Skip to content

Commit

Permalink
Paste file/folder to other folder that already contain file/folder wi…
Browse files Browse the repository at this point in the history
…th the same name

Signed-off-by: Lital Avigad <lital.avigad@sap.com>
  • Loading branch information
litalav authored and amiramw committed Dec 2, 2020
1 parent f1e37fb commit 2baecc9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/filesystem/src/browser/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2baecc9

Please sign in to comment.