Skip to content

Commit 5ae4448

Browse files
committed
[dart:io] Provide epoch timestamps in the FileStat notFound object.
This is a breaking change. #40706 The dummy object returned if FileStat.stat() and FileStat.statSync() fail now contains Unix epoch timestamps instead of null for the accessed, changed, and modified getters. These timestamps are always non-null if the API succeeds and the timestamps are meaningless when the API fails and returns the FileSystemEntityType.notFound type. This change makes the timestamps always non-null, which avoids all legitimate accesses needing a needless null check when Dart becomes null safe. This change is consistent with the mode and size getters that are initialized to non-null dummy values when the API fail. The NNBD migration required making subtle changes to some dart:io semantics in order to provide a better API. This change backports one of these semantic changes to the unmigrated SDK so any issues can be discovered now instead of blocking the future SDK unfork. Change-Id: Iff6b34d04b60f4c9f4cf8d9dd0679f721d142ba4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136585 Reviewed-by: Lasse R.H. Nielsen <[email protected]>
1 parent 4c6a2ab commit 5ae4448

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ used (see Issue [39627][]).
6161
`ProcessStartMode.inheritStdio`) upon accessing the `stdin`, `stdout`, and
6262
`stderr` getters. Previously these getters would all return `null`.
6363

64+
* **Breaking change** [#40706](https://github.com/dart-lang/sdk/issues/40706):
65+
The dummy object returned if `FileStat.stat()` and `FileStat.statSync()` fail
66+
now contains Unix epoch timestamps instead of `null` for the `accessed`,
67+
`changed`, and `modified` getters.
68+
6469
#### `dart:mirrors`
6570

6671
* Added `MirrorSystem.neverType`.

sdk/lib/io/file_system_entity.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class FileStat {
5959
static const _mode = 4;
6060
static const _size = 5;
6161

62-
static const _notFound = const FileStat._internalNotFound();
62+
static final _epoch = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true);
63+
static final _notFound = new FileStat._internal(
64+
_epoch, _epoch, _epoch, FileSystemEntityType.notFound, 0, -1);
6365

6466
/**
6567
* The time of the last change to the data or metadata of the file system
@@ -105,14 +107,6 @@ class FileStat {
105107
FileStat._internal(this.changed, this.modified, this.accessed, this.type,
106108
this.mode, this.size);
107109

108-
const FileStat._internalNotFound()
109-
: changed = null,
110-
modified = null,
111-
accessed = null,
112-
type = FileSystemEntityType.notFound,
113-
mode = 0,
114-
size = -1;
115-
116110
external static _statSync(_Namespace namespace, String path);
117111

118112
/**

0 commit comments

Comments
 (0)