Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 6ef5815

Browse files
authored
Fix MemoryFile to update last modified time when writeAs* is called (#50)
1 parent 8f5f853 commit 6ef5815

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#### 2.3.1
2+
3+
* Fixed `MemoryFileSystem` to make `File.writeAs...()` update the last modified
4+
time of the file.
5+
16
#### 2.3.0
27

38
* Added the following convenience methods in `Directory`:

lib/src/backends/memory/memory_file.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class _MemoryFile extends _MemoryFileSystemEntity implements File {
235235
_FileNode node = _resolvedBackingOrCreate;
236236
_truncateIfNecessary(node, mode);
237237
node.content.addAll(bytes);
238+
node.touch();
238239
}
239240

240241
@override

lib/src/backends/memory/node.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ abstract class _RealNode extends _Node {
8484

8585
/// The size of the file system entity in bytes.
8686
int get size;
87+
88+
/// Updates the last modified time of the node.
89+
void touch() {
90+
modified = new DateTime.now().millisecondsSinceEpoch;
91+
}
8792
}
8893

8994
/// Class that represents the backing for an in-memory directory.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: file
2-
version: 2.3.0
2+
version: 2.3.1
33
authors:
44
- Matan Lurey <[email protected]>
55
- Yegor Jbanov <[email protected]>

test/common_tests.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,15 @@ void runCommonTests(
24922492
f.writeAsBytesSync(<int>[]);
24932493
expect(f.readAsBytesSync(), <int>[]);
24942494
});
2495+
2496+
test('updatesLastModifiedTime', () async {
2497+
File f = fs.file(ns('/foo'))..createSync();
2498+
DateTime before = f.statSync().modified;
2499+
await new Future<Null>.delayed(const Duration(seconds: 2));
2500+
f.writeAsBytesSync(<int>[1, 2, 3]);
2501+
DateTime after = f.statSync().modified;
2502+
expect(after, isAfter(before));
2503+
});
24952504
});
24962505

24972506
group('writeAsString', () {

test/utils.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Matcher isSameOrBefore(DateTime time) => new _IsSameOrBefore(time);
3636
/// the specified [time].
3737
Matcher isSameOrAfter(DateTime time) => new _IsSameOrAfter(time);
3838

39+
/// Successfully matches against a [DateTime] that is after the specified
40+
/// [time].
41+
Matcher isAfter(DateTime time) => new _IsAfter(time);
42+
3943
abstract class _CompareDateTime extends Matcher {
4044
final DateTime _time;
4145
final Matcher _matcher;
@@ -93,3 +97,13 @@ class _IsSameOrAfter extends _CompareDateTime {
9397
@override
9498
String get mismatchAdjective => 'before';
9599
}
100+
101+
class _IsAfter extends _CompareDateTime {
102+
const _IsAfter(DateTime time) : super(time, isPositive);
103+
104+
@override
105+
String get descriptionOperator => '>';
106+
107+
@override
108+
String get mismatchAdjective => 'before';
109+
}

0 commit comments

Comments
 (0)