Chromium Code Reviews| 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..f9c44cef20b56bbefed7a5c1fb37f2165acf4a3b 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) { |
|
scheglov
2015/02/24 17:44:54
Should we add new tests for this method?
danrubel
2015/02/25 19:43:05
Good point. I thought this class was test code, bu
|
| + _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 resouce: $child'; |
|
scheglov
2015/02/24 17:44:54
resource
danrubel
2015/02/25 19:43:05
Done.
|
| + } |
| + } |
| + _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) { |