[flutter_tools] handle FileSystemException trying to delete temp directory from core_devices.dart (#140415)
Fixes https://github.com/flutter/flutter/issues/140416, the top crasher on stable/3.16.4
This commit is contained in:
committed by
GitHub
parent
ea6017ded8
commit
ef1227f05d
@@ -5,6 +5,7 @@
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../base/error_handling_io.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
@@ -101,7 +102,7 @@ class IOSCoreDeviceControl {
|
||||
_logger.printError('Error executing devicectl: $err');
|
||||
return <Object?>[];
|
||||
} finally {
|
||||
tempDirectory.deleteSync(recursive: true);
|
||||
ErrorHandlingFileSystem.deleteIfExists(tempDirectory, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ void main() {
|
||||
exceptionHandler = FileExceptionHandler();
|
||||
});
|
||||
|
||||
testWithoutContext('bypasses error handling when withAllowedFailure is used', () {
|
||||
testWithoutContext('bypasses error handling when noExitOnFailure is used', () {
|
||||
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
|
||||
delegate: MemoryFileSystem.test(opHandle: exceptionHandler.opHandle),
|
||||
platform: windowsPlatform,
|
||||
@@ -123,9 +123,9 @@ void main() {
|
||||
FileSystemOp.write,
|
||||
FileSystemException('', file.path, const OSError('', kUserPermissionDenied)),
|
||||
);
|
||||
|
||||
final Matcher throwsNonToolExit = throwsA(isNot(isA<ToolExit>()));
|
||||
expect(() => ErrorHandlingFileSystem.noExitOnFailure(
|
||||
() => file.writeAsStringSync('')), throwsException);
|
||||
() => file.writeAsStringSync('')), throwsNonToolExit);
|
||||
|
||||
// nesting does not unconditionally re-enable errors.
|
||||
expect(() {
|
||||
@@ -133,7 +133,7 @@ void main() {
|
||||
ErrorHandlingFileSystem.noExitOnFailure(() { });
|
||||
file.writeAsStringSync('');
|
||||
});
|
||||
}, throwsException);
|
||||
}, throwsNonToolExit);
|
||||
|
||||
// Check that state does not leak.
|
||||
expect(() => file.writeAsStringSync(''), throwsToolExit());
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.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/version.dart';
|
||||
import 'package:flutter_tools/src/ios/core_devices.dart';
|
||||
@@ -35,7 +36,7 @@ void main() {
|
||||
version: Version(14, 0, 0),
|
||||
);
|
||||
xcode = Xcode.test(
|
||||
processManager: FakeProcessManager.any(),
|
||||
processManager: fakeProcessManager,
|
||||
xcodeProjectInterpreter: xcodeProjectInterpreter,
|
||||
);
|
||||
deviceControl = IOSCoreDeviceControl(
|
||||
@@ -86,6 +87,7 @@ void main() {
|
||||
setUp(() {
|
||||
logger = BufferLogger.test();
|
||||
fakeProcessManager = FakeProcessManager.empty();
|
||||
// TODO(fujino): make this FakeProcessManager.empty()
|
||||
xcode = Xcode.test(processManager: FakeProcessManager.any());
|
||||
deviceControl = IOSCoreDeviceControl(
|
||||
logger: logger,
|
||||
@@ -1322,6 +1324,37 @@ invalid JSON
|
||||
});
|
||||
|
||||
group('list devices', () {
|
||||
testWithoutContext('Handles FileSystemException deleting temp directory', () async {
|
||||
final Directory tempDir = fileSystem.systemTempDirectory
|
||||
.childDirectory('core_devices.rand0');
|
||||
final File tempFile = tempDir.childFile('core_device_list.json');
|
||||
final List<String> args = <String>[
|
||||
'xcrun',
|
||||
'devicectl',
|
||||
'list',
|
||||
'devices',
|
||||
'--timeout',
|
||||
'5',
|
||||
'--json-output',
|
||||
tempFile.path,
|
||||
];
|
||||
fakeProcessManager.addCommand(FakeCommand(
|
||||
command: args,
|
||||
onRun: () {
|
||||
// Simulate that this command threw and simulataneously the OS
|
||||
// deleted the temp directory
|
||||
expect(tempFile, exists);
|
||||
tempDir.deleteSync(recursive: true);
|
||||
expect(tempFile, isNot(exists));
|
||||
throw ProcessException(args.first, args.sublist(1));
|
||||
},
|
||||
));
|
||||
|
||||
await deviceControl.getCoreDevices();
|
||||
expect(logger.errorText, contains('Error executing devicectl: ProcessException'));
|
||||
expect(fakeProcessManager, hasNoRemainingExpectations);
|
||||
});
|
||||
|
||||
testWithoutContext('No devices', () async {
|
||||
const String deviceControlOutput = '''
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user