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

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

Issue 2844903002: Extend file-system abstraction with a couple methods, remove context (Closed)
Patch Set: fix test in windows bot Created 3 years, 8 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/front_end/lib/kernel_generator.dart ('k') | pkg/front_end/lib/physical_file_system.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 e7382adfb38a38d51b534894d9c7ce6de27d1a25..6c57167a87d45e1620fadab02a82fe585658256d 100644
--- a/pkg/front_end/lib/memory_file_system.dart
+++ b/pkg/front_end/lib/memory_file_system.dart
@@ -8,8 +8,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
-import 'package:path/path.dart' as p;
-
import 'file_system.dart';
/// Concrete implementation of [FileSystem] which performs its operations on an
@@ -17,10 +15,13 @@ import 'file_system.dart';
///
/// Not intended to be implemented or extended by clients.
class MemoryFileSystem implements FileSystem {
- @override
- final p.Context context;
-
final Map<Uri, Uint8List> _files = {};
+ final Map<Uri, DateTime> _lastModified = {};
+
+ // Counter used to create mock last-modification timestamps. The memory
+ // file-system is mainly used for testing, so we use mock timestamps to avoid
+ // introducing non-determinism.
+ int _lastUpdate = 0;
/// The "current directory" in the in-memory virtual file system.
///
@@ -29,7 +30,7 @@ class MemoryFileSystem implements FileSystem {
/// Always ends in a trailing '/'.
Uri currentDirectory;
- MemoryFileSystem(this.context, Uri currentDirectory)
+ MemoryFileSystem(Uri currentDirectory)
: currentDirectory = _addTrailingSlash(currentDirectory);
@override
@@ -80,12 +81,24 @@ class MemoryFileSystemEntity implements FileSystemEntity {
return UTF8.decode(contents);
}
+ @override
+ Future<bool> exists() async => _fileSystem._files[uri] != null;
+
+ @override
+ Future<DateTime> lastModified() async {
+ var lastModified = _fileSystem._lastModified[uri];
+ if (lastModified == null) {
+ throw new Exception('File does not exist');
+ }
+ return lastModified;
+ }
+
/// Writes the given raw bytes to this file system entity.
///
/// If no file exists, one is created. If a file exists already, it is
/// overwritten.
void writeAsBytesSync(List<int> bytes) {
- _fileSystem._files[uri] = new Uint8List.fromList(bytes);
+ _update(uri, new Uint8List.fromList(bytes));
}
/// Writes the given string to this file system entity.
@@ -98,6 +111,12 @@ class MemoryFileSystemEntity implements FileSystemEntity {
// Note: the return type of UTF8.encode is List<int>, but in practice it
// always returns Uint8List. We rely on that for efficiency, so that we
// don't have to make an extra copy.
- _fileSystem._files[uri] = UTF8.encode(s) as Uint8List;
+ _update(uri, UTF8.encode(s) as Uint8List);
+ }
+
+ void _update(Uri uri, Uint8List data) {
+ _fileSystem._files[uri] = data;
+ _fileSystem._lastModified[uri] =
+ new DateTime.fromMicrosecondsSinceEpoch(++_fileSystem._lastUpdate);
}
}
« no previous file with comments | « pkg/front_end/lib/kernel_generator.dart ('k') | pkg/front_end/lib/physical_file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698