Skip to content

Commit a2b298e

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/core): rename to itself should be a noop
1 parent 9180b9d commit a2b298e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/angular_devkit/core/src/virtual-fs/host/record.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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)) {

packages/angular_devkit/core/src/virtual-fs/host/record_spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)