Skip to content

Commit

Permalink
Handle copying when source and target destinations are the same
Browse files Browse the repository at this point in the history
Fixes #4812

- Fixes an issue when calling `copy` from the filesystem when
the `source` and `target` destinations are the same. Currently,
no check is performed to verify if the paths are different
which leads to `fs-extra` throwing an error.

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Apr 5, 2019
1 parent b1df8fc commit 947f559
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/filesystem/src/node/node-filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ export class FileSystemNode implements FileSystem {
if (targetStat && !overwrite) {
throw FileSystemError.FileExists(targetUri, "Did you set the 'overwrite' flag to true?");
}
if (targetStat && targetStat.uri === sourceStat.uri) {
throw FileSystemError.FileExists(targetUri, 'Cannot perform copy, source and destination are the same.');
}
await fs.copy(FileUri.fsPath(_sourceUri), FileUri.fsPath(_targetUri), { overwrite, recursive });
const newStat = await this.doGetStat(_targetUri, 1);
if (newStat) {
Expand Down

0 comments on commit 947f559

Please sign in to comment.