Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(765)

Unified Diff: pkg/analyzer/lib/file_system/memory_file_system.dart

Issue 941883002: cache pub list results (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/test_all.dart ('k') | pkg/analyzer/lib/source/pub_package_map_provider.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « pkg/analysis_server/test/test_all.dart ('k') | pkg/analyzer/lib/source/pub_package_map_provider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698