Skip to content

Commit

Permalink
Fix file deletion crash in BuildIOSArchiveCommand.runCommand (#138734)
Browse files Browse the repository at this point in the history
  • Loading branch information
vashworth authored Nov 20, 2023
1 parent 82170c1 commit e826c63
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/flutter_tools/lib/src/commands/build_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:unified_analytics/unified_analytics.dart';

import '../base/analyze_size.dart';
import '../base/common.dart';
import '../base/error_handling_io.dart';
import '../base/logger.dart';
import '../base/process.dart';
import '../base/utils.dart';
Expand Down Expand Up @@ -492,7 +493,9 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
],
);
} finally {
generatedExportPlist?.deleteSync();
if (generatedExportPlist != null) {
ErrorHandlingFileSystem.deleteIfExists(generatedExportPlist);
}
status?.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void main() {
FakeCommand exportArchiveCommand({
String exportOptionsPlist = '/ExportOptions.plist',
File? cachePlist,
bool deleteExportOptionsPlist = false,
}) {
return FakeCommand(
command: <String>[
Expand All @@ -201,6 +202,9 @@ void main() {
if (cachePlist != null) {
cachePlist.writeAsStringSync(fileSystem.file(_exportOptionsPlist).readAsStringSync());
}
if (deleteExportOptionsPlist) {
fileSystem.file(_exportOptionsPlist).deleteSync();
}
}
);
}
Expand Down Expand Up @@ -419,6 +423,40 @@ void main() {
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});

testUsingContext('ipa build ignores deletion failure if generatedExportPlist does not exist', () async {
final File cachedExportOptionsPlist = fileSystem.file('/CachedExportOptions.plist');
final BuildCommand command = BuildCommand(
artifacts: artifacts,
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
logger: logger,
fileSystem: fileSystem,
processUtils: processUtils,
osUtils: FakeOperatingSystemUtils(),
);
fakeProcessManager.addCommands(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(),
exportArchiveCommand(
exportOptionsPlist: _exportOptionsPlist,
cachePlist: cachedExportOptionsPlist,
deleteExportOptionsPlist: true,
),
]);
createMinimalMockProjectFiles();

await createTestCommandRunner(command).run(
const <String>['build', 'ipa', '--no-pub']
);
expect(fakeProcessManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
Logger: () => logger,
ProcessManager: () => fakeProcessManager,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});

testUsingContext('ipa build invokes xcodebuild and archives for app store', () async {
final File cachedExportOptionsPlist = fileSystem.file('/CachedExportOptions.plist');
final BuildCommand command = BuildCommand(
Expand Down

0 comments on commit e826c63

Please sign in to comment.