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

Unified Diff: pkg/front_end/lib/memory_file_system.dart

Issue 2994643002: Add createDirectory() to MemoryFileSystemEntity. (Closed)
Patch Set: Created 3 years, 4 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 | « no previous file | pkg/front_end/test/memory_file_system_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/memory_file_system.dart
diff --git a/pkg/front_end/lib/memory_file_system.dart b/pkg/front_end/lib/memory_file_system.dart
index b5515b77251149aeeb41a1ba10e4a53741d24b39..015134968670bcb8985020c19a478adee1e9d0f9 100644
--- a/pkg/front_end/lib/memory_file_system.dart
+++ b/pkg/front_end/lib/memory_file_system.dart
@@ -16,6 +16,7 @@ import 'file_system.dart';
/// Not intended to be implemented or extended by clients.
class MemoryFileSystem implements FileSystem {
final Map<Uri, Uint8List> _files = {};
+ final Set<Uri> _directories = new Set<Uri>();
/// The "current directory" in the in-memory virtual file system.
///
@@ -60,8 +61,25 @@ class MemoryFileSystemEntity implements FileSystemEntity {
other.uri == uri &&
identical(other._fileSystem, _fileSystem);
+ /// Create a directory for this file system entry.
+ ///
+ /// If the entry already exists, either as a file, or as a directory,
+ /// this is an error.
+ void createDirectory() {
+ if (_fileSystem._files[uri] != null) {
+ throw new FileSystemException(uri, 'Entry $uri is a file.');
+ }
+ if (_fileSystem._directories.contains(uri)) {
+ throw new FileSystemException(uri, 'Directory $uri already exists.');
+ }
+ _fileSystem._directories.add(uri);
+ }
+
@override
- Future<bool> exists() async => _fileSystem._files[uri] != null;
+ Future<bool> exists() async {
+ return _fileSystem._files[uri] != null ||
+ _fileSystem._directories.contains(uri);
+ }
@override
Future<List<int>> readAsBytes() async {
@@ -104,6 +122,9 @@ class MemoryFileSystemEntity implements FileSystemEntity {
}
void _update(Uri uri, Uint8List data) {
+ if (_fileSystem._directories.contains(uri)) {
+ throw new FileSystemException(uri, 'Entry $uri is a directory.');
+ }
_fileSystem._files[uri] = data;
}
}
« no previous file with comments | « no previous file | pkg/front_end/test/memory_file_system_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698