Unverified Commit bdc06194 authored by xster's avatar xster Committed by GitHub

Prompt a solution message when flutter tools network fail in China (#16244)

parent d6d87447
...@@ -51,7 +51,15 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t ...@@ -51,7 +51,15 @@ if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; t
mkdir -p -- "$DART_SDK_PATH" mkdir -p -- "$DART_SDK_PATH"
DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME" DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME"
curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || {
echo
echo "Failed to retrieve the Dart SDK at $DART_SDK_URL"
echo "If you're located in China, please follow"
echo "https://github.com/flutter/flutter/wiki/Using-Flutter-in-China"
echo
rm -f -- "$DART_SDK_ZIP"
exit 1
}
unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || { unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || {
echo echo
echo "It appears that the downloaded file is corrupt; please try the operation again later." echo "It appears that the downloaded file is corrupt; please try the operation again later."
......
...@@ -8,6 +8,7 @@ import 'package:meta/meta.dart'; ...@@ -8,6 +8,7 @@ import 'package:meta/meta.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/io.dart' show SocketException;
import 'base/logger.dart'; import 'base/logger.dart';
import 'base/net.dart'; import 'base/net.dart';
import 'base/os.dart'; import 'base/os.dart';
...@@ -28,6 +29,10 @@ class Cache { ...@@ -28,6 +29,10 @@ class Cache {
} }
} }
static const List<String> _hostsBlockedInChina = const <String> [
'storage.googleapis.com',
];
final Directory _rootOverride; final Directory _rootOverride;
final List<CachedArtifact> _artifacts = <CachedArtifact>[]; final List<CachedArtifact> _artifacts = <CachedArtifact>[];
...@@ -190,9 +195,21 @@ class Cache { ...@@ -190,9 +195,21 @@ class Cache {
Future<Null> updateAll() async { Future<Null> updateAll() async {
if (!_lockEnabled) if (!_lockEnabled)
return null; return null;
for (CachedArtifact artifact in _artifacts) { try {
if (!artifact.isUpToDate()) for (CachedArtifact artifact in _artifacts) {
await artifact.update(); if (!artifact.isUpToDate())
await artifact.update();
}
} on SocketException catch (e) {
if (_hostsBlockedInChina.contains(e.address?.host)) {
printError(
'Failed to retrieve Flutter tool depedencies: ${e.message}.\n'
"If you're in China, please follow "
'https://github.com/flutter/flutter/wiki/Using-Flutter-in-China',
emphasis: true,
);
}
rethrow;
} }
} }
} }
......
...@@ -11,6 +11,7 @@ import 'package:test/test.dart'; ...@@ -11,6 +11,7 @@ import 'package:test/test.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/base/io.dart' show InternetAddress, SocketException;
import 'src/context.dart'; import 'src/context.dart';
...@@ -76,6 +77,31 @@ void main() { ...@@ -76,6 +77,31 @@ void main() {
verifyNever(artifact1.update()); verifyNever(artifact1.update());
verify(artifact2.update()); verify(artifact2.update());
}); });
testUsingContext('failed storage.googleapis.com download shows China warning', () async {
final CachedArtifact artifact1 = new MockCachedArtifact();
final CachedArtifact artifact2 = new MockCachedArtifact();
when(artifact1.isUpToDate()).thenReturn(false);
when(artifact2.isUpToDate()).thenReturn(false);
final MockInternetAddress address = new MockInternetAddress();
when(address.host).thenReturn('storage.googleapis.com');
when(artifact1.update()).thenThrow(new SocketException(
'Connection reset by peer',
address: address,
));
final Cache cache = new Cache(artifacts: <CachedArtifact>[artifact1, artifact2]);
try {
await cache.updateAll();
fail('Mock thrown exception expected');
} catch (e) {
verify(artifact1.update());
// Don't continue when retrieval fails.
verifyNever(artifact2.update());
expect(
testLogger.errorText,
contains('https://github.com/flutter/flutter/wiki/Using-Flutter-in-China'),
);
}
});
}); });
testUsingContext('flattenNameSubdirs', () { testUsingContext('flattenNameSubdirs', () {
...@@ -103,3 +129,4 @@ class MockFile extends Mock implements File { ...@@ -103,3 +129,4 @@ class MockFile extends Mock implements File {
class MockRandomAccessFile extends Mock implements RandomAccessFile {} class MockRandomAccessFile extends Mock implements RandomAccessFile {}
class MockCachedArtifact extends Mock implements CachedArtifact {} class MockCachedArtifact extends Mock implements CachedArtifact {}
class MockInternetAddress extends Mock implements InternetAddress {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment