Skip to content

Commit

Permalink
[null-safety] migrate to _almost_ null safety (dart-lang/file#162)
Browse files Browse the repository at this point in the history
Remove record/replay functionality and update to almost null-safety.
  • Loading branch information
jonahwilliams authored Jul 29, 2020
1 parent 1f0ab00 commit 9532537
Show file tree
Hide file tree
Showing 80 changed files with 186 additions and 5,244 deletions.
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
analyzer:
enable-experiment:
- non-nullable
strong-mode:
implicit-casts: false
implicit-dynamic: false
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ install:
build: off

test_script:
- pub run test -j1
- pub run --enable-experiment=non-nullable test -j1
4 changes: 2 additions & 2 deletions dev/bots/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ elif [[ "$SHARD" == "analyze" ]]; then
for package in "${PACKAGES[@]}"; do
echo "Analyzing packages/$package"
cd $ROOT/packages/$package
dartanalyzer --options=$ROOT/analysis_options.yaml . || exit $?
dartanalyzer --enable-experiment=non-nullable --options=$ROOT/analysis_options.yaml . || exit $?
done
else
# tests shard
cd $ROOT/packages/file
pub run test -j1 -rexpanded || exit $?
pub run --enable-experiment=non-nullable test -j1 -rexpanded || exit $?
fi
6 changes: 4 additions & 2 deletions pkgs/file/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#### 5.2.2-dev
#### 6.0.0-nullsafety

* Made `MemoryRandomAccessFile` and `MemoryFile.openWrite` handle the file
* Update to null safety.
* Remove record/replay functionality.
* Made `MemoryRandomAccessFile` and `MemoryFile.openWrite` handle the file.
being removed or renamed while open.
* Fixed incorrect formatting in `NoMatchingInvocationError.toString()`.
* Fixed more test flakiness.
Expand Down
2 changes: 2 additions & 0 deletions pkgs/file/lib/chroot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// A file system that provides a view into _another_ `FileSystem` via a path.
export 'src/backends/chroot.dart';
2 changes: 2 additions & 0 deletions pkgs/file/lib/file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// Core interfaces containing the abstract `FileSystem` interface definition
/// and all associated types used by `FileSystem`.
export 'src/forwarding.dart';
Expand Down
2 changes: 2 additions & 0 deletions pkgs/file/lib/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// A local file system implementation. This relies on the use of `dart:io`
/// and is thus not suitable for use in the browser.
export 'src/backends/local.dart';
2 changes: 2 additions & 0 deletions pkgs/file/lib/memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// An implementation of `FileSystem` that exists entirely in memory with an
/// internal representation loosely based on the Filesystem Hierarchy Standard.
export 'src/backends/memory.dart';
14 changes: 0 additions & 14 deletions pkgs/file/lib/record_replay.dart

This file was deleted.

1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/chroot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
library file.src.backends.chroot;

import 'dart:async';
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/chroot/chroot_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
part of file.src.backends.chroot;

class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
Expand Down
3 changes: 2 additions & 1 deletion pkgs/file/lib/src/backends/chroot/chroot_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
part of file.src.backends.chroot;

typedef _SetupCallback = dynamic Function();
Expand Down Expand Up @@ -251,7 +252,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
getDelegate(followLinks: true).openSync(mode: mode);

@override
Stream<Uint8List> openRead([int start, int end]) =>
Stream<Uint8List> openRead([int? start, int? end]) =>
getDelegate(followLinks: true).openRead(start, end).cast<Uint8List>();

@override
Expand Down
15 changes: 9 additions & 6 deletions pkgs/file/lib/src/backends/chroot/chroot_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
part of file.src.backends.chroot;

const String _thisDir = '.';
Expand Down Expand Up @@ -51,10 +52,10 @@ class ChrootFileSystem extends FileSystem {
/// Directory in [delegate] file system that is treated as the root here.
final String root;

String _systemTemp;
String? _systemTemp;

/// Path to the synthetic current working directory in this file system.
String _cwd;
late String _cwd;

/// Gets the root path, as seen by entities in this file system.
String get _localRoot => delegate.path.rootPrefix(root);
Expand Down Expand Up @@ -255,7 +256,7 @@ class ChrootFileSystem extends FileSystem {
/// the partially resolved path will be returned.
String _resolve(
String path, {
String from,
String? from,
bool followLinks = true,
_NotFoundBehavior notFound = _NotFoundBehavior.allow,
}) {
Expand Down Expand Up @@ -366,14 +367,16 @@ enum _NotFoundBehavior {
class _NotFoundFileStat implements FileStat {
const _NotFoundFileStat();

static final DateTime _empty = DateTime(0);

@override
DateTime get changed => null;
DateTime get changed => _empty;

@override
DateTime get modified => null;
DateTime get modified => _empty;

@override
DateTime get accessed => null;
DateTime get accessed => _empty;

@override
FileSystemEntityType get type => FileSystemEntityType.notFound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
part of file.src.backends.chroot;

abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/chroot/chroot_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
part of file.src.backends.chroot;

class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
export 'local/local_file_system.dart' show LocalFileSystem;
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/local/local_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'package:file/src/common.dart' as common;
import 'package:file/src/forwarding.dart';
import 'package:file/src/io.dart' as io;
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/local/local_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'package:file/src/forwarding.dart';
import 'package:file/src/io.dart' as io;
import 'package:file/file.dart';
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/local/local_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'dart:async';

import 'package:file/src/io.dart' as io;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'package:file/src/forwarding.dart';
import 'package:file/src/io.dart' as io;
import 'package:file/file.dart';
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/local/local_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'package:file/src/forwarding.dart';
import 'package:file/src/io.dart' as io;
import 'package:file/file.dart';
Expand Down
1 change: 1 addition & 0 deletions pkgs/file/lib/src/backends/memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
export 'memory/memory_file_system.dart' show MemoryFileSystem;
export 'memory/style.dart' show FileSystemStyle, StyleableFileSystem;
4 changes: 3 additions & 1 deletion pkgs/file/lib/src/backends/memory/clock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10

/// Interface describing clocks used by the [MemoryFileSystem].
///
/// The [MemoryFileSystem] uses a clock to determine the modification times of
Expand Down Expand Up @@ -39,7 +41,7 @@ class _RealtimeClock extends Clock {

class _MonotonicTestClock extends Clock {
_MonotonicTestClock({
DateTime start,
DateTime? start,
}) : _current = start ?? DateTime(2000);

DateTime _current;
Expand Down
3 changes: 2 additions & 1 deletion pkgs/file/lib/src/backends/memory/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'package:file/src/common.dart' as common;

/// Generates a path to use in error messages.
typedef PathGenerator = dynamic Function();

/// Throws a `FileSystemException` if [object] is null.
void checkExists(Object object, PathGenerator path) {
void checkExists(Object? object, PathGenerator path) {
if (object == null) {
throw common.noSuchFileOrDirectory(path() as String);
}
Expand Down
14 changes: 8 additions & 6 deletions pkgs/file/lib/src/backends/memory/memory_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.10
import 'dart:async';

import 'package:file/file.dart';
Expand Down Expand Up @@ -39,7 +40,7 @@ class MemoryDirectory extends MemoryFileSystemEntity
}

@override
bool existsSync() => backingOrNull?.stat?.type == expectedType;
bool existsSync() => backingOrNull?.stat.type == expectedType;

@override
Future<Directory> create({bool recursive = false}) async {
Expand All @@ -49,7 +50,7 @@ class MemoryDirectory extends MemoryFileSystemEntity

@override
void createSync({bool recursive = false}) {
Node node = internalCreateSync(
Node? node = internalCreateSync(
followTailLink: true,
visitLinks: true,
createChild: (DirectoryNode parent, bool isFinalSegment) {
Expand All @@ -59,17 +60,18 @@ class MemoryDirectory extends MemoryFileSystemEntity
return null;
},
);
if (node.type != expectedType) {
if (node?.type != expectedType) {
// There was an existing non-directory node at this object's path
throw common.notADirectory(path);
}
}

@override
Future<Directory> createTemp([String prefix]) async => createTempSync(prefix);
Future<Directory> createTemp([String? prefix]) async =>
createTempSync(prefix);

@override
Directory createTempSync([String prefix]) {
Directory createTempSync([String? prefix]) {
prefix = (prefix ?? '') + 'rand';
String fullPath = fileSystem.path.join(path, prefix);
String dirname = fileSystem.path.dirname(fullPath);
Expand Down Expand Up @@ -142,7 +144,7 @@ class MemoryDirectory extends MemoryFileSystemEntity
while (followLinks &&
utils.isLink(child) &&
breadcrumbs.add(child as LinkNode)) {
Node referent = (child as LinkNode).referentOrNull;
Node? referent = child.referentOrNull;
if (referent != null) {
child = referent;
}
Expand Down
Loading

0 comments on commit 9532537

Please sign in to comment.