Don't throw StateError when listing core devices during tool shutdown (#160094)
The previous attempt at this fix was assuming that the tool's file system was a `LocalFileSystem`, but in reality it's a `LocalFileSystem` wrapped in an `ErrorHandlingFileSystem`. This change takes this into account. Fixes https://github.com/flutter/flutter/issues/160082 Fixes https://github.com/flutter/flutter/issues/156962 --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import 'dart:io' as io show Directory, File, Link, Process, ProcessException, Pr
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as p; // flutter_ignore: package_path_import
|
||||
import 'package:process/process.dart';
|
||||
|
||||
@@ -47,7 +46,6 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
|
||||
_platform = platform,
|
||||
super(delegate);
|
||||
|
||||
@visibleForTesting
|
||||
FileSystem get fileSystem => delegate;
|
||||
|
||||
final Platform _platform;
|
||||
|
||||
@@ -79,7 +79,13 @@ class IOSCoreDeviceControl {
|
||||
|
||||
try {
|
||||
final RunResult result = await _processUtils.run(command, throwOnError: true);
|
||||
final bool isToolPossiblyShutdown = _fileSystem is LocalFileSystem && _fileSystem.disposed;
|
||||
bool isToolPossiblyShutdown = false;
|
||||
if (_fileSystem is ErrorHandlingFileSystem) {
|
||||
final FileSystem delegate = _fileSystem.fileSystem;
|
||||
if (delegate is LocalFileSystem) {
|
||||
isToolPossiblyShutdown = delegate.disposed;
|
||||
}
|
||||
}
|
||||
|
||||
// It's possible that the tool is in the process of shutting down, which
|
||||
// could result in the temp directory being deleted after the shutdown hooks run
|
||||
@@ -94,10 +100,6 @@ class IOSCoreDeviceControl {
|
||||
_logger.printError('The process exited with code ${result.exitCode} and');
|
||||
_logger.printError('Stdout:\n\n${result.stdout.trim()}\n');
|
||||
_logger.printError('Stderr:\n\n${result.stderr.trim()}');
|
||||
_logger.printError('Using file system type: ${_fileSystem.runtimeType}');
|
||||
if (_fileSystem is LocalFileSystem) {
|
||||
_logger.printError('LocalFileSystem disposed: ${_fileSystem.disposed}');
|
||||
}
|
||||
throw StateError('Expected the file ${output.path} to exist but it did not');
|
||||
} else if (isToolPossiblyShutdown) {
|
||||
return <Object?>[];
|
||||
|
||||
@@ -4,25 +4,44 @@
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/signals.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/version.dart';
|
||||
import 'package:flutter_tools/src/ios/core_devices.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/macos/xcode.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/fake_process_manager.dart';
|
||||
|
||||
class LocalFileSystemFake extends LocalFileSystem {
|
||||
LocalFileSystemFake.test({required super.signals}) : super.test();
|
||||
|
||||
class LocalFileSystemFake extends Fake implements LocalFileSystem {
|
||||
MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
|
||||
|
||||
@override
|
||||
Directory get systemTempDirectory => memoryFileSystem.systemTempDirectory;
|
||||
|
||||
@override
|
||||
Directory directory(dynamic path) => memoryFileSystem.directory(path);
|
||||
|
||||
@override
|
||||
File file(dynamic path) => memoryFileSystem.file(path);
|
||||
|
||||
@override
|
||||
Context get path => memoryFileSystem.path;
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get disposed => _disposed;
|
||||
|
||||
bool _disposed = false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
@@ -1411,12 +1430,13 @@ invalid JSON
|
||||
});
|
||||
|
||||
testWithoutContext('Handles file system disposal', () async {
|
||||
final LocalFileSystem localFs = LocalFileSystemFake.test(signals: Signals.test());
|
||||
final LocalFileSystem localFs = LocalFileSystemFake();
|
||||
final ErrorHandlingFileSystem fs = ErrorHandlingFileSystem(delegate: localFs, platform: FakePlatform());
|
||||
deviceControl = IOSCoreDeviceControl(
|
||||
logger: logger,
|
||||
processManager: fakeProcessManager,
|
||||
xcode: xcode,
|
||||
fileSystem: localFs,
|
||||
fileSystem: fs,
|
||||
);
|
||||
final Directory tempDir = localFs.systemTempDirectory
|
||||
.childDirectory('core_devices.rand0');
|
||||
|
||||
Reference in New Issue
Block a user