mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrate flutter_tools file_system to null safety (#78896)
This commit is contained in:
parent
2415eca4d2
commit
46c99809b4
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/local.dart' as local_fs;
|
||||
import 'package:meta/meta.dart';
|
||||
@ -31,8 +29,8 @@ class FileNotFoundException implements IOException {
|
||||
/// Various convenience file system methods.
|
||||
class FileSystemUtils {
|
||||
FileSystemUtils({
|
||||
@required FileSystem fileSystem,
|
||||
@required Platform platform,
|
||||
required FileSystem fileSystem,
|
||||
required Platform platform,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_platform = platform;
|
||||
|
||||
@ -86,8 +84,8 @@ class FileSystemUtils {
|
||||
///
|
||||
/// Returns false, if [entity] exists, but [referenceFile] does not.
|
||||
bool isOlderThanReference({
|
||||
@required FileSystemEntity entity,
|
||||
@required File referenceFile,
|
||||
required FileSystemEntity entity,
|
||||
required File referenceFile,
|
||||
}) {
|
||||
if (!entity.existsSync()) {
|
||||
return true;
|
||||
@ -97,8 +95,8 @@ class FileSystemUtils {
|
||||
}
|
||||
|
||||
/// Return the absolute path of the user's home directory.
|
||||
String get homeDirPath {
|
||||
String path = _platform.isWindows
|
||||
String? get homeDirPath {
|
||||
String? path = _platform.isWindows
|
||||
? _platform.environment['USERPROFILE']
|
||||
: _platform.environment['HOME'];
|
||||
if (path != null) {
|
||||
@ -123,8 +121,8 @@ String getDisplayPath(String fullPath, FileSystem fileSystem) {
|
||||
void copyDirectory(
|
||||
Directory srcDir,
|
||||
Directory destDir, {
|
||||
bool Function(File srcFile, File destFile) shouldCopyFile,
|
||||
void Function(File srcFile, File destFile) onFileCopied,
|
||||
bool Function(File srcFile, File destFile)? shouldCopyFile,
|
||||
void Function(File srcFile, File destFile)? onFileCopied,
|
||||
}) {
|
||||
if (!srcDir.existsSync()) {
|
||||
throw Exception('Source directory "${srcDir.path}" does not exist, nothing to copy');
|
||||
@ -167,13 +165,13 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
|
||||
|
||||
@visibleForTesting
|
||||
LocalFileSystem.test({
|
||||
@required Signals signals,
|
||||
required Signals signals,
|
||||
List<ProcessSignal> fatalSignals = Signals.defaultExitSignals,
|
||||
}) : this(signals, fatalSignals, null);
|
||||
|
||||
Directory _systemTemp;
|
||||
Directory? _systemTemp;
|
||||
final Map<ProcessSignal, Object> _signalTokens = <ProcessSignal, Object>{};
|
||||
final ShutdownHooks _shutdownHooks;
|
||||
final ShutdownHooks? _shutdownHooks;
|
||||
|
||||
Future<void> dispose() async {
|
||||
_tryToDeleteTemp();
|
||||
@ -189,7 +187,7 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
|
||||
void _tryToDeleteTemp() {
|
||||
try {
|
||||
if (_systemTemp?.existsSync() ?? false) {
|
||||
_systemTemp.deleteSync(recursive: true);
|
||||
_systemTemp?.deleteSync(recursive: true);
|
||||
}
|
||||
} on FileSystemException {
|
||||
// ignore.
|
||||
@ -225,6 +223,6 @@ class LocalFileSystem extends local_fs.LocalFileSystem {
|
||||
_tryToDeleteTemp,
|
||||
);
|
||||
}
|
||||
return _systemTemp;
|
||||
return _systemTemp!;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user