[flutter_tools] move gradle download failure handling into tool (#68140)

This crash affects anyone using flutter, so move it into the tool where it can be tested and documented. Ensure it works on windows devicelab too.
This commit is contained in:
Jonah Williams
2020-10-15 09:20:52 -07:00
committed by GitHub
parent e800de1a5e
commit 2321b72dfb
3 changed files with 82 additions and 7 deletions

View File

@@ -4,6 +4,8 @@
import 'package:meta/meta.dart';
import '../base/error_handling_io.dart';
import '../base/file_system.dart';
import '../base/process.dart';
import '../base/terminal.dart';
import '../globals.dart' as globals;
@@ -96,8 +98,14 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
eventLabel: 'permission-denied',
);
// Gradle crashes for several known reasons when downloading that are not
// actionable by flutter.
/// Gradle crashes for several known reasons when downloading that are not
/// actionable by Flutter.
///
/// The Gradle cache directory must be deleted, otherwise it may attempt to
/// re-use the bad zip file.
///
/// See also:
/// * https://docs.gradle.org/current/userguide/directory_layout.html#dir:gradle_user_home
@visibleForTesting
final GradleHandledError networkErrorHandler = GradleHandledError(
test: _lineMatcher(const <String>[
@@ -120,6 +128,15 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
'$warningMark Gradle threw an error while downloading artifacts from the network. '
'Retrying to download...'
);
try {
final String homeDir = globals.platform.environment['HOME'];
if (homeDir != null) {
final Directory directory = globals.fs.directory(globals.fs.path.join(homeDir, '.gradle'));
ErrorHandlingFileSystem.deleteIfExists(directory, recursive: true);
}
} on FileSystemException catch (err) {
globals.printTrace('Failed to delete Gradle cache: $err');
}
return GradleBuildStatus.retry;
},
eventLabel: 'network',