Skip to content

Commit 9ce7505

Browse files
author
Benjamin Pasero
committed
move - send a copy event instead of move when move is across providers
1 parent f2d1806 commit 9ce7505

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/vs/workbench/services/files2/common/fileService2.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ export class FileService2 extends Disposable implements IFileService {
355355
const targetProvider = this.throwIfFileSystemIsReadonly(await this.withProvider(target));
356356

357357
// move
358-
await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'move', overwrite);
358+
const mode = await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'move', overwrite);
359359

360360
// resolve and send events
361361
const fileStat = await this.resolveFile(target, { resolveMetadata: true });
362-
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.MOVE, fileStat));
362+
this._onAfterOperation.fire(new FileOperationEvent(source, mode === 'move' ? FileOperation.MOVE : FileOperation.COPY, fileStat));
363363

364364
return fileStat;
365365
}
@@ -369,16 +369,16 @@ export class FileService2 extends Disposable implements IFileService {
369369
const targetProvider = this.throwIfFileSystemIsReadonly(await this.withProvider(target));
370370

371371
// copy
372-
await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'copy', overwrite);
372+
const mode = await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'copy', overwrite);
373373

374374
// resolve and send events
375375
const fileStat = await this.resolveFile(target, { resolveMetadata: true });
376-
this._onAfterOperation.fire(new FileOperationEvent(source, FileOperation.COPY, fileStat));
376+
this._onAfterOperation.fire(new FileOperationEvent(source, mode === 'copy' ? FileOperation.COPY : FileOperation.MOVE, fileStat));
377377

378378
return fileStat;
379379
}
380380

381-
private async doMoveCopy(sourceProvider: IFileSystemProvider, source: URI, targetProvider: IFileSystemProvider, target: URI, mode: 'move' | 'copy', overwrite?: boolean): Promise<void> {
381+
private async doMoveCopy(sourceProvider: IFileSystemProvider, source: URI, targetProvider: IFileSystemProvider, target: URI, mode: 'move' | 'copy', overwrite?: boolean): Promise<'move' | 'copy'> {
382382

383383
// validation
384384
const { exists, isCaseChange } = await this.doValidateMoveCopy(sourceProvider, source, targetProvider, target, overwrite);
@@ -396,7 +396,7 @@ export class FileService2 extends Disposable implements IFileService {
396396

397397
// same provider with fast copy: leverage copy() functionality
398398
if (sourceProvider === targetProvider && hasFileFolderCopyCapability(sourceProvider)) {
399-
return sourceProvider.copy(source, target, { overwrite: !!overwrite });
399+
return sourceProvider.copy(source, target, { overwrite: !!overwrite }).then(() => mode);
400400
}
401401

402402
// otherwise, ensure we got the capabilities to do this
@@ -411,9 +411,9 @@ export class FileService2 extends Disposable implements IFileService {
411411
// traverse the source if it is a folder and not a file
412412
const sourceFile = await this.resolveFile(source);
413413
if (sourceFile.isDirectory) {
414-
return this.doCopyFolder(sourceProvider, sourceFile, targetProvider, target, overwrite);
414+
return this.doCopyFolder(sourceProvider, sourceFile, targetProvider, target, overwrite).then(() => mode);
415415
} else {
416-
return this.doCopyFile(sourceProvider, source, targetProvider, target, overwrite);
416+
return this.doCopyFile(sourceProvider, source, targetProvider, target, overwrite).then(() => mode);
417417
}
418418
}
419419

@@ -422,14 +422,14 @@ export class FileService2 extends Disposable implements IFileService {
422422

423423
// same provider: leverage rename() functionality
424424
if (sourceProvider === targetProvider) {
425-
return sourceProvider.rename(source, target, { overwrite: !!overwrite });
425+
return sourceProvider.rename(source, target, { overwrite: !!overwrite }).then(() => mode);
426426
}
427427

428428
// across providers: copy to target & delete at source
429429
else {
430430
await this.doMoveCopy(sourceProvider, source, targetProvider, target, 'copy', overwrite);
431431

432-
return this.del(source, { recursive: true });
432+
return this.del(source, { recursive: true }).then(() => 'copy' as 'move' | 'copy');
433433
}
434434
}
435435
}

src/vs/workbench/services/files2/test/node/diskFileService.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ suite('Disk File Service', () => {
487487
assert.equal(existsSync(source.fsPath), false);
488488
assert.ok(event!);
489489
assert.equal(event!.resource.fsPath, source.fsPath);
490-
assert.equal(event!.operation, FileOperation.MOVE);
490+
assert.equal(event!.operation, FileOperation.COPY);
491491
assert.equal(event!.target!.resource.fsPath, renamed.resource.fsPath);
492492

493493
const targetContents = readFileSync(target.fsPath);
@@ -574,7 +574,7 @@ suite('Disk File Service', () => {
574574
assert.equal(existsSync(source.fsPath), false);
575575
assert.ok(event!);
576576
assert.equal(event!.resource.fsPath, source.fsPath);
577-
assert.equal(event!.operation, FileOperation.MOVE);
577+
assert.equal(event!.operation, FileOperation.COPY);
578578
assert.equal(event!.target!.resource.fsPath, renamed.resource.fsPath);
579579

580580
const targetChildren = readdirSync(target.fsPath);

0 commit comments

Comments
 (0)