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

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

Issue 1808213004: Add File.renameSync() to virtual file system. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
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 d3ec74f11019eab7cb5860dc94258c8de1661664..b15b256b2e239657c029a96fff0a2aaa28a19348 100644
--- a/pkg/analyzer/lib/file_system/memory_file_system.dart
+++ b/pkg/analyzer/lib/file_system/memory_file_system.dart
@@ -159,6 +159,21 @@ class MemoryResourceProvider implements ResourceProvider {
}
}
+ void renameFileSync(String path, String newPath) {
+ if (newPath == path) {
+ return;
+ }
+ if (_pathToResource[newPath] is _MemoryFolder) {
+ throw new FileSystemException(
+ path, 'Could not be renamed: $newPath is a folder.');
+ }
+ _pathToResource.remove(path);
+ _pathToContent[newPath] = _pathToContent.remove(path);
+ _pathToBytes[newPath] = _pathToBytes.remove(path);
+ _pathToTimestamp[newPath] = _pathToTimestamp.remove(path);
+ _pathToWatchers[newPath] = _pathToWatchers.remove(path);
Brian Wilkerson 2016/03/17 19:31:00 Does this need to call _notifyWatchers?
+ }
+
File updateFile(String path, String content, [int stamp]) {
path = pathContext.normalize(path);
newFolder(pathContext.dirname(path));
@@ -214,7 +229,9 @@ class MemoryResourceProvider implements ResourceProvider {
});
}
- void _setFileBytes(String path, List<int> bytes) {
+ void _setFileBytes(_MemoryFile file, List<int> bytes) {
+ String path = file.path;
+ _pathToResource[path] = file;
_pathToBytes[path] = bytes;
_pathToTimestamp[path] = nextStamp++;
_notifyWatchers(path, ChangeType.MODIFY);
@@ -271,6 +288,11 @@ class _MemoryDummyLink extends _MemoryResource implements File {
}
@override
+ Resource renameSync(String newPath) {
+ throw new FileSystemException(path, 'File could not be renamed');
+ }
+
+ @override
void writeAsBytesSync(List<int> bytes) {
throw new FileSystemException(path, 'File could not be written');
}
@@ -335,8 +357,14 @@ class _MemoryFile extends _MemoryResource implements File {
}
@override
+ File renameSync(String newPath) {
+ _provider.renameFileSync(path, newPath);
+ return _provider._newFile(newPath);
+ }
+
+ @override
void writeAsBytesSync(List<int> bytes) {
- _provider._setFileBytes(path, bytes);
+ _provider._setFileBytes(this, bytes);
}
}
« no previous file with comments | « pkg/analyzer/lib/file_system/file_system.dart ('k') | pkg/analyzer/lib/file_system/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698