| Index: pkg/analyzer/lib/file_system/memory_file_system.dart
|
| diff --git a/pkg/analyzer/lib/file_system/memory_file_system.dart b/pkg/analyzer/lib/file_system/memory_file_system.dart
|
| index efb779ccd12447ce6b20ac32cd054bf7686a8193..daba7f59e0151272044102f2af1baf2dc7e31547 100644
|
| --- a/pkg/analyzer/lib/file_system/memory_file_system.dart
|
| +++ b/pkg/analyzer/lib/file_system/memory_file_system.dart
|
| @@ -31,6 +31,9 @@ class MemoryResourceProvider implements ResourceProvider {
|
| @override
|
| Context get pathContext => posix;
|
|
|
| + /**
|
| + * Delete the file with the given path.
|
| + */
|
| void deleteFile(String path) {
|
| _checkFileAtPath(path);
|
| _pathToResource.remove(path);
|
| @@ -39,6 +42,28 @@ class MemoryResourceProvider implements ResourceProvider {
|
| _notifyWatchers(path, ChangeType.REMOVE);
|
| }
|
|
|
| + /**
|
| + * Delete the folder with the given path
|
| + * and recurively delete nested files and folders.
|
| + */
|
| + void deleteFolder(String path) {
|
| + _checkFolderAtPath(path);
|
| + _MemoryFolder folder = _pathToResource[path];
|
| + for (Resource child in folder.getChildren()) {
|
| + if (child is File) {
|
| + deleteFile(child.path);
|
| + } else if (child is Folder) {
|
| + deleteFolder(child.path);
|
| + } else {
|
| + throw 'failed to delete resource: $child';
|
| + }
|
| + }
|
| + _pathToResource.remove(path);
|
| + _pathToContent.remove(path);
|
| + _pathToTimestamp.remove(path);
|
| + _notifyWatchers(path, ChangeType.REMOVE);
|
| + }
|
| +
|
| @override
|
| Resource getResource(String path) {
|
| path = posix.normalize(path);
|
| @@ -75,13 +100,13 @@ class MemoryResourceProvider implements ResourceProvider {
|
| return link;
|
| }
|
|
|
| - File newFile(String path, String content) {
|
| + File newFile(String path, String content, [int stamp]) {
|
| path = posix.normalize(path);
|
| newFolder(posix.dirname(path));
|
| _MemoryFile file = new _MemoryFile(this, path);
|
| _pathToResource[path] = file;
|
| _pathToContent[path] = content;
|
| - _pathToTimestamp[path] = nextStamp++;
|
| + _pathToTimestamp[path] = stamp != null ? stamp : nextStamp++;
|
| _notifyWatchers(path, ChangeType.ADD);
|
| return file;
|
| }
|
| @@ -118,6 +143,14 @@ class MemoryResourceProvider implements ResourceProvider {
|
| }
|
| }
|
|
|
| + void _checkFolderAtPath(String path) {
|
| + _MemoryResource resource = _pathToResource[path];
|
| + if (resource is! _MemoryFolder) {
|
| + throw new ArgumentError(
|
| + 'Folder expected at "$path" but ${resource.runtimeType} found');
|
| + }
|
| + }
|
| +
|
| void _notifyWatchers(String path, ChangeType changeType) {
|
| _pathToWatchers.forEach(
|
| (String watcherPath, List<StreamController<WatchEvent>> streamControllers) {
|
|
|