Skip to content

Commit 292695e

Browse files
bkonyiandrewkolos
andauthored
Don't throw StateError when listing core devices during tool shutdown (flutter#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 flutter#160082 Fixes flutter#156962 --------- Co-authored-by: Andrew Kolos <[email protected]>
1 parent 8cdb333 commit 292695e

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

packages/flutter_tools/lib/src/base/error_handling_io.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:io' as io show Directory, File, Link, Process, ProcessException, Pr
77
import 'dart:typed_data';
88

99
import 'package:file/file.dart';
10-
import 'package:meta/meta.dart';
1110
import 'package:path/path.dart' as p; // flutter_ignore: package_path_import
1211
import 'package:process/process.dart';
1312

@@ -47,7 +46,6 @@ class ErrorHandlingFileSystem extends ForwardingFileSystem {
4746
_platform = platform,
4847
super(delegate);
4948

50-
@visibleForTesting
5149
FileSystem get fileSystem => delegate;
5250

5351
final Platform _platform;

packages/flutter_tools/lib/src/ios/core_devices.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ class IOSCoreDeviceControl {
7979

8080
try {
8181
final RunResult result = await _processUtils.run(command, throwOnError: true);
82-
final bool isToolPossiblyShutdown = _fileSystem is LocalFileSystem && _fileSystem.disposed;
82+
bool isToolPossiblyShutdown = false;
83+
if (_fileSystem is ErrorHandlingFileSystem) {
84+
final FileSystem delegate = _fileSystem.fileSystem;
85+
if (delegate is LocalFileSystem) {
86+
isToolPossiblyShutdown = delegate.disposed;
87+
}
88+
}
8389

8490
// It's possible that the tool is in the process of shutting down, which
8591
// could result in the temp directory being deleted after the shutdown hooks run
@@ -94,10 +100,6 @@ class IOSCoreDeviceControl {
94100
_logger.printError('The process exited with code ${result.exitCode} and');
95101
_logger.printError('Stdout:\n\n${result.stdout.trim()}\n');
96102
_logger.printError('Stderr:\n\n${result.stderr.trim()}');
97-
_logger.printError('Using file system type: ${_fileSystem.runtimeType}');
98-
if (_fileSystem is LocalFileSystem) {
99-
_logger.printError('LocalFileSystem disposed: ${_fileSystem.disposed}');
100-
}
101103
throw StateError('Expected the file ${output.path} to exist but it did not');
102104
} else if (isToolPossiblyShutdown) {
103105
return <Object?>[];

packages/flutter_tools/test/general.shard/ios/core_devices_test.dart

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,44 @@
44

55
import 'package:file/memory.dart';
66
import 'package:file_testing/file_testing.dart';
7+
import 'package:flutter_tools/src/base/error_handling_io.dart';
78
import 'package:flutter_tools/src/base/file_system.dart';
89
import 'package:flutter_tools/src/base/io.dart';
910
import 'package:flutter_tools/src/base/logger.dart';
10-
import 'package:flutter_tools/src/base/signals.dart';
11+
import 'package:flutter_tools/src/base/platform.dart';
1112
import 'package:flutter_tools/src/base/version.dart';
1213
import 'package:flutter_tools/src/ios/core_devices.dart';
1314
import 'package:flutter_tools/src/ios/xcodeproj.dart';
1415
import 'package:flutter_tools/src/macos/xcode.dart';
16+
import 'package:test/fake.dart';
1517

1618
import '../../src/common.dart';
1719
import '../../src/fake_process_manager.dart';
1820

19-
class LocalFileSystemFake extends LocalFileSystem {
20-
LocalFileSystemFake.test({required super.signals}) : super.test();
21-
21+
class LocalFileSystemFake extends Fake implements LocalFileSystem {
2222
MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
2323

2424
@override
2525
Directory get systemTempDirectory => memoryFileSystem.systemTempDirectory;
26+
27+
@override
28+
Directory directory(dynamic path) => memoryFileSystem.directory(path);
29+
30+
@override
31+
File file(dynamic path) => memoryFileSystem.file(path);
32+
33+
@override
34+
Context get path => memoryFileSystem.path;
35+
36+
@override
37+
Future<void> dispose() async {
38+
_disposed = true;
39+
}
40+
41+
@override
42+
bool get disposed => _disposed;
43+
44+
bool _disposed = false;
2645
}
2746

2847
void main() {
@@ -1411,12 +1430,13 @@ invalid JSON
14111430
});
14121431

14131432
testWithoutContext('Handles file system disposal', () async {
1414-
final LocalFileSystem localFs = LocalFileSystemFake.test(signals: Signals.test());
1433+
final LocalFileSystem localFs = LocalFileSystemFake();
1434+
final ErrorHandlingFileSystem fs = ErrorHandlingFileSystem(delegate: localFs, platform: FakePlatform());
14151435
deviceControl = IOSCoreDeviceControl(
14161436
logger: logger,
14171437
processManager: fakeProcessManager,
14181438
xcode: xcode,
1419-
fileSystem: localFs,
1439+
fileSystem: fs,
14201440
);
14211441
final Directory tempDir = localFs.systemTempDirectory
14221442
.childDirectory('core_devices.rand0');

0 commit comments

Comments
 (0)