mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] do not use IOSink for writing cache responses (#67231)
Any File-derived IOSink may throw un-handleable async exceptions into the zone, see dart-lang/sdk#43663 . Instead, just write to a file with an append mode.
This commit is contained in:
parent
fdd1bf2944
commit
4ce2a7aa6d
@ -1598,10 +1598,11 @@ class ArtifactUpdater {
|
||||
);
|
||||
try {
|
||||
_ensureExists(tempFile.parent);
|
||||
final IOSink ioSink = tempFile.openWrite();
|
||||
await _download(url, ioSink);
|
||||
await ioSink.flush();
|
||||
await ioSink.close();
|
||||
if (tempFile.existsSync()) {
|
||||
tempFile.deleteSync();
|
||||
}
|
||||
await _download(url, tempFile);
|
||||
|
||||
if (!tempFile.existsSync()) {
|
||||
throw Exception('Did not find downloaded file ${tempFile.path}');
|
||||
}
|
||||
@ -1656,13 +1657,15 @@ class ArtifactUpdater {
|
||||
}
|
||||
|
||||
/// Download bytes from [url], throwing non-200 responses as an exception.
|
||||
Future<void> _download(Uri url, IOSink ioSink) async {
|
||||
Future<void> _download(Uri url, File file) async {
|
||||
final HttpClientRequest request = await _httpClient.getUrl(url);
|
||||
final HttpClientResponse response = await request.close();
|
||||
if (response.statusCode != HttpStatus.ok) {
|
||||
throw Exception(response.statusCode);
|
||||
}
|
||||
await response.forEach(ioSink.add);
|
||||
await response.forEach((List<int> chunk) {
|
||||
file.writeAsBytesSync(chunk, mode: FileMode.append);
|
||||
});
|
||||
}
|
||||
|
||||
/// Create a temporary file and invoke [onTemporaryFile] with the file as
|
||||
|
@ -18,7 +18,7 @@ import 'package:mockito/mockito.dart';
|
||||
import '../src/common.dart';
|
||||
import '../src/mocks.dart';
|
||||
|
||||
final Platform testPlatform = FakePlatform(environment: <String, String>{});
|
||||
final Platform testPlatform = FakePlatform(environment: const <String, String>{});
|
||||
|
||||
void main() {
|
||||
testWithoutContext('ArtifactUpdater can download a zip archive', () async {
|
||||
@ -367,6 +367,7 @@ class MockHttpClientResponse extends Mock implements HttpClientResponse {
|
||||
|
||||
@override
|
||||
Future<void> forEach(void Function(List<int> element) action) async {
|
||||
action(<int>[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user