Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy and paste file/folder in the same place will duplicate the file/folder #8940

Closed
wants to merge 1 commit into from

Conversation

i501378
Copy link
Contributor

@i501378 i501378 commented Jan 12, 2021

Signed-off-by: Lital Avigad lital.avigad@sap.com

What it does

Fixes #8933

Select file/folder and press 'Ctrl+C' and 'Ctrl+V' and the file/folder will be duplicated.

How to test

Mark file/folder and press 'Ctrl+C' and 'Ctrl+V'.

Review checklist

Reminder for reviewers

@i501378 i501378 force-pushed the copy-paste-duplicate branch from 5d01773 to bc68f96 Compare January 12, 2021 09:26
…folder fix eclipse-theia#8933

Signed-off-by: Lital Avigad <lital.avigad@sap.com>
@i501378 i501378 force-pushed the copy-paste-duplicate branch from bc68f96 to 345b988 Compare January 12, 2021 09:28
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking care of the issue, I tested and it works well. My only comment is regarding who should actually be responsible for the logic, and I believe it would benefit all copy callers by adding it directly to the service (doCopy).

const parent = await this.fileService.resolve(source.parent);
const name = source.path.name + '_copy';
targetUri = FileSystemUtils.generateUniqueResourceURI(source.parent, parent, name, source.path.ext);
}
try {
await this.fileService.copy(source, targetUri);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should move the logic to the actual implementation of fileService.copy, so all clients (callers) who are requesting a similar behavior will not need to duplicate the logic. For example, the doMoveCopy is handling the _copy like you've done:

// 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);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should move the logic to the actual implementation of fileService.copy

I do not think so. If you debug into the VS Code's FileService, that we copied, you will see the target URI is the expected target URI (file:///path/to/file copy or file:///path/to/file copy 2). Code does not do any more magic just copies/moves the file. We should do the same since we copied the code and we do not want to diverge from it.

By the way, I proposed something similar here

@vince-fugnitto vince-fugnitto added the filesystem issues related to the filesystem label Jan 12, 2021
@i501378
Copy link
Contributor Author

i501378 commented Feb 10, 2021

Hi @kittaakos and @vince-fugnitto ,

I am confused, can you tell me what should I do so this PR will be approved?

Regards,

Lital.

@kittaakos
Copy link
Contributor

kittaakos commented Feb 10, 2021

I am confused, can you tell me what should I do so this PR will be approved?

I am a little bit off from the Theia loops recently so I am just suggesting here, it's up to you how you implement it. I think this is the fix we need: #9037 (comment)

The FileService API should not change the target URI when moving/copying. Imagine you have a Node.js call:

fs.copyFile('/path/to/my/file', '/path/to/desired/destination', cb)

And eventually, it will copy my file to /path/to/desired/destination_copy just because /path/to/desired/destination already exists. No, the FileService should fail and not modify the destination.

@vince-fugnitto
Copy link
Member

@i501378 thank you for the changes 👍 it seems as though the initial issue #8933 is fixed by #9037 so it should be safe to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision_needed issues that require decisions on ways forward (ex: if they should be updated or closed) filesystem issues related to the filesystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy & Paste issues
5 participants