From 0b8d70f413269be3d2a708bcd7e2524901a01ddf Mon Sep 17 00:00:00 2001 From: Teamop Date: Wed, 18 Jul 2018 01:01:24 +0800 Subject: [PATCH] fix(@angular-devkit/core): fix cannot delete directory --- .../core/src/virtual-fs/host/memory.ts | 2 +- .../core/src/virtual-fs/host/memory_spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts index 8863a3d41465..02fb40b869d2 100644 --- a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts +++ b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts @@ -180,7 +180,7 @@ export class SimpleMemoryHost implements Host<{}> { path = this._toAbsolute(path); if (this._isDirectory(path)) { for (const [cachePath] of this._cache.entries()) { - if (path.startsWith(cachePath + NormalizedSep)) { + if (cachePath.startsWith(path + NormalizedSep) || cachePath === path) { this._cache.delete(cachePath); } } diff --git a/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts b/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts index 849829666dc3..45df3e60fb24 100644 --- a/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts +++ b/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts @@ -65,6 +65,22 @@ describe('SimpleMemoryHost', () => { expect(host.exists(normalize('/sub/file1'))).toBe(false); }); + it('can delete directory', () => { + const host = new SyncDelegateHost(new SimpleMemoryHost()); + + const buffer = stringToFileBuffer('hello'); + + expect(host.exists(normalize('/sub/file1'))).toBe(false); + host.write(normalize('/sub/file1'), buffer); + host.write(normalize('/subfile.2'), buffer); + expect(host.exists(normalize('/sub/file1'))).toBe(true); + expect(host.exists(normalize('/subfile.2'))).toBe(true); + host.delete(normalize('/sub')); + expect(host.exists(normalize('/sub/file1'))).toBe(false); + expect(host.exists(normalize('/sub'))).toBe(false); + expect(host.exists(normalize('/subfile.2'))).toBe(true); + }); + it('can rename', () => { const host = new SyncDelegateHost(new SimpleMemoryHost());