Skip to content

Commit 01b7ae0

Browse files
committed
properly handle exists-errors, microsoft#48660
1 parent 6cbbb7e commit 01b7ae0

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/vs/workbench/services/files/electron-browser/remoteFileService.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ export class RemoteFileService extends FileService {
557557
}).then(fileStat => {
558558
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.MOVE, fileStat));
559559
return fileStat;
560+
}, err => {
561+
const result = this._tryParseFileOperationResult(err);
562+
if (result === FileOperationResult.FILE_MOVE_CONFLICT) {
563+
throw new FileOperationError(localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), result);
564+
}
565+
throw err;
560566
});
561567
});
562568
}
@@ -581,7 +587,18 @@ export class RemoteFileService extends FileService {
581587

582588
if (source.scheme === target.scheme && (provider.capabilities & FileSystemProviderCapabilities.FileFolderCopy)) {
583589
// good: provider supports copy withing scheme
584-
return provider.copy(source, target, { overwrite }).then(stat => toIFileStat(provider, [target, stat]));
590+
return provider.copy(source, target, { overwrite }).then(stat => {
591+
return toIFileStat(provider, [target, stat]);
592+
}).then(fileStat => {
593+
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
594+
return fileStat;
595+
}, err => {
596+
const result = this._tryParseFileOperationResult(err);
597+
if (result === FileOperationResult.FILE_MOVE_CONFLICT) {
598+
throw new FileOperationError(localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), result);
599+
}
600+
throw err;
601+
});
585602
}
586603

587604
const prepare = overwrite
@@ -603,7 +620,10 @@ export class RemoteFileService extends FileService {
603620
return fileStat;
604621
});
605622
}, err => {
606-
if (err instanceof Error && err.name === 'ENOPRO') {
623+
const result = this._tryParseFileOperationResult(err);
624+
if (result === FileOperationResult.FILE_MOVE_CONFLICT) {
625+
throw new FileOperationError(localize('fileMoveConflict', "Unable to move/copy. File already exists at destination."), result);
626+
} else if (err instanceof Error && err.name === 'ENOPRO') {
607627
// file scheme
608628
return super.updateContent(target, content.value, { encoding: content.encoding });
609629
} else {

0 commit comments

Comments
 (0)