Skip to content

Commit

Permalink
Copy and paste file/folder in the same place will duplicate the file/…
Browse files Browse the repository at this point in the history
…folder

Signed-off-by: Ron Nabet <ron.nabet@sap.com>
  • Loading branch information
Ron Nabet committed Feb 21, 2021
1 parent 9f7993d commit ee93b93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 0 additions & 8 deletions packages/filesystem/src/browser/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 });
Expand Down
8 changes: 7 additions & 1 deletion packages/filesystem/src/browser/file-tree/file-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -148,8 +149,13 @@ export class FileTreeModel extends TreeModelImpl implements LocationService {
}

async copy(source: URI, target: Readonly<FileStatNode>): Promise<URI> {
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);
Expand Down

0 comments on commit ee93b93

Please sign in to comment.