Skip to content

Commit

Permalink
fix(@angular-devkit/core): fix cannot delete directory (#11574)
Browse files Browse the repository at this point in the history
  • Loading branch information
Teamop authored and hansl committed Sep 25, 2018
1 parent 35dd760 commit b561657
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/angular_devkit/core/src/virtual-fs/host/memory.ts
Expand Up @@ -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);
}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts
Expand Up @@ -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());

Expand Down

0 comments on commit b561657

Please sign in to comment.