Unverified Commit a67df9e1 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix crash during artifact download (#14147)

parent bf7cc096
...@@ -290,7 +290,7 @@ abstract class CachedArtifact { ...@@ -290,7 +290,7 @@ abstract class CachedArtifact {
/// Download an archive from the given [url] and unzip it to [location]. /// Download an archive from the given [url] and unzip it to [location].
Future<Null> _downloadArchive(String message, Uri url, Directory location, bool verifier(File f), void extractor(File f, Directory d)) { Future<Null> _downloadArchive(String message, Uri url, Directory location, bool verifier(File f), void extractor(File f, Directory d)) {
return _withDownloadFile('${_flattenNameSubdirs(url)}', (File tempFile) async { return _withDownloadFile('${flattenNameSubdirs(url)}', (File tempFile) async {
if (!verifier(tempFile)) { if (!verifier(tempFile)) {
final Status status = logger.startProgress(message, expectSlowOperation: true); final Status status = logger.startProgress(message, expectSlowOperation: true);
await _downloadFile(url, tempFile).then<Null>((_) { await _downloadFile(url, tempFile).then<Null>((_) {
...@@ -516,9 +516,10 @@ String _flattenNameNoSubdirs(String fileName) { ...@@ -516,9 +516,10 @@ String _flattenNameNoSubdirs(String fileName) {
return new String.fromCharCodes(replacedCodeUnits); return new String.fromCharCodes(replacedCodeUnits);
} }
String _flattenNameSubdirs(Uri url) { @visibleForTesting
String flattenNameSubdirs(Uri url) {
final List<String> pieces = <String>[url.host]..addAll(url.pathSegments); final List<String> pieces = <String>[url.host]..addAll(url.pathSegments);
final List<String> convertedPieces = pieces.map(_flattenNameNoSubdirs); final Iterable<String> convertedPieces = pieces.map(_flattenNameNoSubdirs);
return fs.path.joinAll(convertedPieces); return fs.path.joinAll(convertedPieces);
} }
......
...@@ -77,6 +77,14 @@ void main() { ...@@ -77,6 +77,14 @@ void main() {
verify(artifact2.update()); verify(artifact2.update());
}); });
}); });
testUsingContext('flattenNameSubdirs', () {
expect(flattenNameSubdirs(Uri.parse('http://flutter.io/foo/bar')), 'flutter.io/foo/bar');
expect(flattenNameSubdirs(Uri.parse('http://docs.flutter.io/foo/bar')), 'docs.flutter.io/foo/bar');
expect(flattenNameSubdirs(Uri.parse('https://www.flutter.io')), 'www.flutter.io');
}, overrides: <Type, Generator>{
FileSystem: () => new MockFileSystem(),
});
} }
class MockFileSystem extends MemoryFileSystem { class MockFileSystem extends MemoryFileSystem {
......
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