File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
packages/angular_devkit/core/src/virtual-fs/host Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -271,12 +271,16 @@ export class CordHost extends SimpleMemoryHost {
271271 ) . pipe (
272272 toArray ( ) ,
273273 switchMap ( ( [ existTo , existFrom ] ) => {
274- if ( existTo ) {
275- return throwError ( new FileAlreadyExistException ( to ) ) ;
276- }
277274 if ( ! existFrom ) {
278275 return throwError ( new FileDoesNotExistException ( from ) ) ;
279276 }
277+ if ( from === to ) {
278+ return of ( ) ;
279+ }
280+
281+ if ( existTo ) {
282+ return throwError ( new FileAlreadyExistException ( to ) ) ;
283+ }
280284
281285 // If we're renaming a file that's been created, shortcircuit to creating the `to` path.
282286 if ( this . _filesToCreate . has ( from ) ) {
Original file line number Diff line number Diff line change @@ -101,6 +101,29 @@ describe('CordHost', () => {
101101 done ( ) ;
102102 } ) ;
103103
104+ it ( 'works (create -> rename (identity))' , done => {
105+ const base = new TestHost ( {
106+ '/hello' : 'world' ,
107+ } ) ;
108+
109+ const host = new CordHost ( base ) ;
110+ host . write ( path `/blue` , fileBuffer `hi` ) . subscribe ( undefined , done . fail ) ;
111+ host . rename ( path `/blue` , path `/blue` ) . subscribe ( undefined , done . fail ) ;
112+
113+ const target = new TestHost ( ) ;
114+ host . commit ( target ) . subscribe ( undefined , done . fail ) ;
115+
116+ // Check that there's only 1 write done.
117+ expect ( target . records . filter ( x => mutatingTestRecord . includes ( x . kind ) ) ) . toEqual ( [
118+ { kind : 'write' , path : path `/blue` } ,
119+ ] ) ;
120+
121+ expect ( target . $exists ( '/hello' ) ) . toBe ( false ) ;
122+ expect ( target . $exists ( '/blue' ) ) . toBe ( true ) ;
123+
124+ done ( ) ;
125+ } ) ;
126+
104127 it ( 'works (create -> rename -> rename)' , done => {
105128 const base = new TestHost ( {
106129 '/hello' : 'world' ,
You can’t perform that action at this time.
0 commit comments