@@ -243,60 +243,40 @@ export class WorkingCopyFileService extends Disposable implements IWorkingCopyFi
243243 // file operation participant
244244 await this . runFileOperationParticipants ( files , move ? FileOperation . MOVE : FileOperation . COPY ) ;
245245
246- // Before doing the heavy operations, check first if source and target
247- // are either identical or are considered to be identical for the file
248- // system. In that case we want the model to stay as is and only do the
249- // raw file operation.
250- const remainingFiles : SourceTargetPair [ ] = [ ] ;
251- for ( const { source, target } of files ) {
252- if ( this . uriIdentityService . extUri . isEqual ( source , target ) ) {
246+ // before event
247+ const event = { correlationId : this . correlationIds ++ , operation : move ? FileOperation . MOVE : FileOperation . COPY , files } ;
248+ await this . _onWillRunWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
249+
250+ try {
251+ for ( const { source, target } of files ) {
252+
253+ // If source and target are not equal, handle dirty working copies
254+ // depending on the operation:
255+ // - move: revert both source and target (if any)
256+ // - copy: revert target (if any)
257+ if ( ! this . uriIdentityService . extUri . isEqual ( source , target ) ) {
258+ const dirtyWorkingCopies = ( move ? [ ...this . getDirty ( source ! ) , ...this . getDirty ( target ) ] : this . getDirty ( target ) ) ;
259+ await Promise . all ( dirtyWorkingCopies . map ( dirtyWorkingCopy => dirtyWorkingCopy . revert ( { soft : true } ) ) ) ;
260+ }
261+
262+ // now we can rename the source to target via file operation
253263 if ( move ) {
254264 stats . push ( await this . fileService . move ( source ! , target , overwrite ) ) ;
255265 } else {
256266 stats . push ( await this . fileService . copy ( source ! , target , overwrite ) ) ;
257267 }
258- } else {
259- remainingFiles . push ( { source, target } ) ;
260- }
261- }
262-
263- // Now handle all the file operations that are not identical files
264- if ( remainingFiles . length > 0 ) {
265-
266- // before event
267- const event = { correlationId : this . correlationIds ++ , operation : move ? FileOperation . MOVE : FileOperation . COPY , files : remainingFiles } ;
268- await this . _onWillRunWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
269-
270-
271- // handle dirty working copies depending on the operation:
272- // - move: revert both source and target (if any)
273- // - copy: revert target (if any)
274- for ( const { source, target } of remainingFiles ) {
275- const dirtyWorkingCopies = ( move ? [ ...this . getDirty ( source ! ) , ...this . getDirty ( target ) ] : this . getDirty ( target ) ) ;
276- await Promise . all ( dirtyWorkingCopies . map ( dirtyWorkingCopy => dirtyWorkingCopy . revert ( { soft : true } ) ) ) ;
277268 }
269+ } catch ( error ) {
278270
279- // now we can rename the source to target via file operation
280- try {
281- for ( const { source, target } of remainingFiles ) {
282- if ( move ) {
283- stats . push ( await this . fileService . move ( source ! , target , overwrite ) ) ;
284- } else {
285- stats . push ( await this . fileService . copy ( source ! , target , overwrite ) ) ;
286- }
287- }
288- } catch ( error ) {
289-
290- // error event
291- await this . _onDidFailWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
292-
293- throw error ;
294- }
271+ // error event
272+ await this . _onDidFailWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
295273
296- // after event
297- await this . _onDidRunWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
274+ throw error ;
298275 }
299276
277+ // after event
278+ await this . _onDidRunWorkingCopyFileOperation . fireAsync ( event , CancellationToken . None ) ;
279+
300280 return stats ;
301281 }
302282
0 commit comments