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

Commit 21dfcff

Browse files
authored
General cleanup of package:file (#81)
* Fix/update analysis options * Fix some linter errors * Run dartfmt * Fix some Dart 2 strong-mode type checks * Remove usage of "part" and "part of" in the forwarding, memory, and local backends. * Fix AppVeyor and Travis scripts to work only for Dart 2 * Comment out test that's causing problems with newer SDKs
1 parent 2b00b23 commit 21dfcff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+716
-529
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Dart template
22
# Don’t commit the following directories created by pub.
33
.buildlog
4+
.dart_tool/
45
.pub/
56
build/
67
packages

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: dart
22

33
dart:
4-
- stable
54
- dev
65

76
dart_task:

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
#### 4.0.0
1+
#### 4.0.1
22

3-
* Change method signature for `RecordingRandomAccessFile._close` to return a
4-
`Future<void>` instead of `Future<RandomAccessFile>`. This follows a change in
3+
* General library cleanup
4+
5+
#### 4.0.0
6+
7+
* Change method signature for `RecordingRandomAccessFile._close` to return a
8+
`Future<void>` instead of `Future<RandomAccessFile>`. This follows a change in
59
dart:io, Dart SDK `2.0.0-dev.40`.
610

711
#### 3.0.0

analysis_options.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
analyzer:
2-
strong-mode: true
2+
strong-mode:
3+
implicit-dynamic: false
34
language:
4-
enableStrictCallChecks: true
5+
enablePreviewDart2: true
56
enableSuperMixins: true
67
errors:
78
# treat missing required parameters as a warning (not a hint)
@@ -63,7 +64,7 @@ linter:
6364
- type_annotate_public_apis
6465
- type_init_formals
6566
# TODO - unawaited_futures (https://github.com/dart-lang/linter/issues/419)
66-
- unnecessary_brace_in_string_interp
67+
- unnecessary_brace_in_string_interps
6768
- unnecessary_getters_setters
6869

6970
# === pub rules ===

appveyor.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
install:
2-
- choco install dart-sdk
2+
- ps: wget https://storage.googleapis.com/dart-archive/channels/dev/release/latest/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip
3+
- cmd: echo "Unzipping dart-sdk..."
4+
- cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul
35
- ps: refreshenv
4-
- refreshenv
5-
- set DART_DIR=c:\tools\dart-sdk\bin
6-
- set PUB_EXECUTABLE=pub.bat
6+
- set PATH=%PATH%;C:\tools\dart-sdk\bin
7+
- set PATH=%PATH%;%APPDATA%\Pub\Cache\bin
78
- ps: pwd
89
- pub get
910

1011
build: off
1112

1213
test_script:
13-
- pub run test
14+
- pub run test -j1

lib/src/backends/chroot/chroot_directory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
part of file.src.backends.chroot;
66

77
class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
8-
with ForwardingDirectory, common.DirectoryAddOnsMixin {
8+
with ForwardingDirectory<Directory>, common.DirectoryAddOnsMixin {
99
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);
1010

1111
factory _ChrootDirectory.wrapped(

lib/src/backends/chroot/chroot_file.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
257257
@override
258258
IOSink openWrite({
259259
FileMode mode: FileMode.WRITE,
260-
Encoding encoding: UTF8,
260+
Encoding encoding: utf8,
261261
}) =>
262262
getDelegate(followLinks: true).openWrite(mode: mode, encoding: encoding);
263263

@@ -270,19 +270,19 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
270270
getDelegate(followLinks: true).readAsBytesSync();
271271

272272
@override
273-
Future<String> readAsString({Encoding encoding: UTF8}) =>
273+
Future<String> readAsString({Encoding encoding: utf8}) =>
274274
getDelegate(followLinks: true).readAsString(encoding: encoding);
275275

276276
@override
277-
String readAsStringSync({Encoding encoding: UTF8}) =>
277+
String readAsStringSync({Encoding encoding: utf8}) =>
278278
getDelegate(followLinks: true).readAsStringSync(encoding: encoding);
279279

280280
@override
281-
Future<List<String>> readAsLines({Encoding encoding: UTF8}) =>
281+
Future<List<String>> readAsLines({Encoding encoding: utf8}) =>
282282
getDelegate(followLinks: true).readAsLines(encoding: encoding);
283283

284284
@override
285-
List<String> readAsLinesSync({Encoding encoding: UTF8}) =>
285+
List<String> readAsLinesSync({Encoding encoding: utf8}) =>
286286
getDelegate(followLinks: true).readAsLinesSync(encoding: encoding);
287287

288288
@override
@@ -310,7 +310,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
310310
Future<File> writeAsString(
311311
String contents, {
312312
FileMode mode: FileMode.WRITE,
313-
Encoding encoding: UTF8,
313+
Encoding encoding: utf8,
314314
bool flush: false,
315315
}) async =>
316316
wrap(await getDelegate(followLinks: true).writeAsString(
@@ -324,7 +324,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
324324
void writeAsStringSync(
325325
String contents, {
326326
FileMode mode: FileMode.WRITE,
327-
Encoding encoding: UTF8,
327+
Encoding encoding: utf8,
328328
bool flush: false,
329329
}) =>
330330
getDelegate(followLinks: true).writeAsStringSync(

lib/src/backends/local.dart

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library file.src.backends.local;
6-
7-
import 'dart:async';
8-
9-
import 'package:file/src/common.dart' as common;
10-
import 'package:file/src/forwarding.dart';
11-
import 'package:file/src/io.dart' as io;
12-
import 'package:file/file.dart';
13-
import 'package:path/path.dart' as p;
14-
15-
part 'local/local_directory.dart';
16-
part 'local/local_file.dart';
17-
part 'local/local_file_system.dart';
18-
part 'local/local_file_system_entity.dart';
19-
part 'local/local_link.dart';
5+
export 'local/local_file_system.dart' show LocalFileSystem;

lib/src/backends/local/local_directory.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.local;
5+
import 'package:file/src/common.dart' as common;
6+
import 'package:file/src/forwarding.dart';
7+
import 'package:file/src/io.dart' as io;
8+
import 'package:file/file.dart';
69

7-
class _LocalDirectory
8-
extends _LocalFileSystemEntity<_LocalDirectory, io.Directory>
9-
with ForwardingDirectory, common.DirectoryAddOnsMixin {
10-
_LocalDirectory(FileSystem fs, io.Directory delegate) : super(fs, delegate);
10+
import 'local_file_system_entity.dart';
11+
12+
/// [Directory] implementation that forwards all calls to `dart:io`.
13+
class LocalDirectory extends LocalFileSystemEntity<LocalDirectory, io.Directory>
14+
with ForwardingDirectory<LocalDirectory>, common.DirectoryAddOnsMixin {
15+
/// Instantiates a new [LocalDirectory] tied to the specified file system
16+
/// and delegating to the specified [delegate].
17+
LocalDirectory(FileSystem fs, io.Directory delegate) : super(fs, delegate);
1118

1219
@override
1320
String toString() => "LocalDirectory: '$path'";

lib/src/backends/local/local_file.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.local;
5+
import 'package:file/src/forwarding.dart';
6+
import 'package:file/src/io.dart' as io;
7+
import 'package:file/file.dart';
68

7-
class _LocalFile extends _LocalFileSystemEntity<File, io.File>
9+
import 'local_file_system_entity.dart';
10+
11+
/// [File] implementation that forwards all calls to `dart:io`.
12+
class LocalFile extends LocalFileSystemEntity<File, io.File>
813
with ForwardingFile {
9-
_LocalFile(FileSystem fs, io.File delegate) : super(fs, delegate);
14+
/// Instantiates a new [LocalFile] tied to the specified file system
15+
/// and delegating to the specified [delegate].
16+
LocalFile(FileSystem fs, io.File delegate) : super(fs, delegate);
1017

1118
@override
1219
String toString() => "LocalFile: '$path'";

lib/src/backends/local/local_file_system.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.local;
5+
import 'dart:async';
6+
7+
import 'package:file/src/io.dart' as io;
8+
import 'package:file/file.dart';
9+
import 'package:path/path.dart' as p;
10+
11+
import 'local_directory.dart';
12+
import 'local_file.dart';
13+
import 'local_link.dart';
614

715
/// A wrapper implementation around `dart:io`'s implementation.
816
///
@@ -14,13 +22,13 @@ class LocalFileSystem extends FileSystem {
1422

1523
@override
1624
Directory directory(dynamic path) =>
17-
new _LocalDirectory(this, new io.Directory(getPath(path)));
25+
new LocalDirectory(this, new io.Directory(getPath(path)));
1826

1927
@override
20-
File file(dynamic path) => new _LocalFile(this, new io.File(getPath(path)));
28+
File file(dynamic path) => new LocalFile(this, new io.File(getPath(path)));
2129

2230
@override
23-
Link link(dynamic path) => new _LocalLink(this, new io.Link(getPath(path)));
31+
Link link(dynamic path) => new LocalLink(this, new io.Link(getPath(path)));
2432

2533
@override
2634
p.Context get path => new p.Context();
@@ -30,7 +38,7 @@ class LocalFileSystem extends FileSystem {
3038
/// platform-dependent, and may be set by an environment variable.
3139
@override
3240
Directory get systemTempDirectory =>
33-
new _LocalDirectory(this, io.Directory.systemTemp);
41+
new LocalDirectory(this, io.Directory.systemTemp);
3442

3543
@override
3644
Directory get currentDirectory => directory(io.Directory.current.path);

lib/src/backends/local/local_file_system_entity.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.local;
5+
import 'package:file/src/forwarding.dart';
6+
import 'package:file/src/io.dart' as io;
7+
import 'package:file/file.dart';
68

7-
abstract class _LocalFileSystemEntity<T extends FileSystemEntity,
9+
import 'local_directory.dart';
10+
import 'local_file.dart';
11+
import 'local_link.dart';
12+
13+
/// [FileSystemEntity] implementation that forwards all calls to `dart:io`.
14+
abstract class LocalFileSystemEntity<T extends FileSystemEntity,
815
D extends io.FileSystemEntity> extends ForwardingFileSystemEntity<T, D> {
916
@override
1017
final FileSystem fileSystem;
1118

1219
@override
1320
final D delegate;
1421

15-
_LocalFileSystemEntity(this.fileSystem, this.delegate);
22+
/// Instantiates a new [LocalFileSystemEntity] tied to the specified file
23+
/// system and delegating to the specified [delegate].
24+
LocalFileSystemEntity(this.fileSystem, this.delegate);
1625

1726
@override
1827
String get dirname => fileSystem.path.dirname(path);
@@ -22,11 +31,11 @@ abstract class _LocalFileSystemEntity<T extends FileSystemEntity,
2231

2332
@override
2433
Directory wrapDirectory(io.Directory delegate) =>
25-
new _LocalDirectory(fileSystem, delegate);
34+
new LocalDirectory(fileSystem, delegate);
2635

2736
@override
28-
File wrapFile(io.File delegate) => new _LocalFile(fileSystem, delegate);
37+
File wrapFile(io.File delegate) => new LocalFile(fileSystem, delegate);
2938

3039
@override
31-
Link wrapLink(io.Link delegate) => new _LocalLink(fileSystem, delegate);
40+
Link wrapLink(io.Link delegate) => new LocalLink(fileSystem, delegate);
3241
}

lib/src/backends/local/local_link.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.local;
5+
import 'package:file/src/forwarding.dart';
6+
import 'package:file/src/io.dart' as io;
7+
import 'package:file/file.dart';
68

7-
class _LocalLink extends _LocalFileSystemEntity<Link, io.Link>
9+
import 'local_file_system_entity.dart';
10+
11+
/// [Link] implementation that forwards all calls to `dart:io`.
12+
class LocalLink extends LocalFileSystemEntity<Link, io.Link>
813
with ForwardingLink {
9-
_LocalLink(FileSystem fs, io.Link delegate) : super(fs, delegate);
14+
/// Instantiates a new [LocalLink] tied to the specified file system
15+
/// and delegating to the specified [delegate].
16+
LocalLink(FileSystem fs, io.Link delegate) : super(fs, delegate);
1017

1118
@override
1219
String toString() => "LocalLink: '$path'";

lib/src/backends/memory.dart

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library file.src.backends.memory;
6-
7-
import 'dart:async';
8-
import 'dart:convert';
9-
import 'dart:math' show min;
10-
11-
import 'package:file/file.dart';
12-
import 'package:file/src/common.dart' as common;
13-
import 'package:file/src/io.dart' as io;
14-
import 'package:path/path.dart' as p;
15-
16-
part 'memory/memory_directory.dart';
17-
part 'memory/memory_file.dart';
18-
part 'memory/memory_file_stat.dart';
19-
part 'memory/memory_file_system.dart';
20-
part 'memory/memory_file_system_entity.dart';
21-
part 'memory/memory_link.dart';
22-
part 'memory/node.dart';
23-
part 'memory/utils.dart';
5+
export 'memory/memory_file_system.dart' show MemoryFileSystem;

lib/src/backends/memory/common.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:file/src/common.dart' as common;
6+
7+
/// The file separator.
8+
const String separator = '/';
9+
10+
/// Generates a path to use in error messages.
11+
typedef dynamic PathGenerator();
12+
13+
/// Throws a `FileSystemException` if [object] is null.
14+
void checkExists(Object object, PathGenerator path) {
15+
if (object == null) {
16+
throw common.noSuchFileOrDirectory(path());
17+
}
18+
}

0 commit comments

Comments
 (0)