-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
5d01773
to
bc68f96
Compare
…folder fix eclipse-theia#8933 Signed-off-by: Lital Avigad <lital.avigad@sap.com>
bc68f96
to
345b988
Compare
There was a problem hiding this 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); |
There was a problem hiding this comment.
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:
theia/packages/filesystem/src/browser/file-service.ts
Lines 1120 to 1125 in 5db308f
// 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); | |
} |
There was a problem hiding this comment.
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
Hi @kittaakos and @vince-fugnitto , I am confused, can you tell me what should I do so this PR will be approved? Regards, Lital. |
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 fs.copyFile('/path/to/my/file', '/path/to/desired/destination', cb) And eventually, it will copy my file to |
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