| 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);
|
| }
|
| }
|
|
|