From a67df9e1d144ea1c03e49cf3c7f30f0d5f5c32ef Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 17 Jan 2018 16:08:19 -0800 Subject: [PATCH] Fix crash during artifact download (#14147) --- packages/flutter_tools/lib/src/cache.dart | 7 ++++--- packages/flutter_tools/test/cache_test.dart | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 12f7656dc7..ba657bf08b 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -290,7 +290,7 @@ abstract class CachedArtifact { /// Download an archive from the given [url] and unzip it to [location]. Future _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)) { final Status status = logger.startProgress(message, expectSlowOperation: true); await _downloadFile(url, tempFile).then((_) { @@ -516,9 +516,10 @@ String _flattenNameNoSubdirs(String fileName) { return new String.fromCharCodes(replacedCodeUnits); } -String _flattenNameSubdirs(Uri url) { +@visibleForTesting +String flattenNameSubdirs(Uri url) { final List pieces = [url.host]..addAll(url.pathSegments); - final List convertedPieces = pieces.map(_flattenNameNoSubdirs); + final Iterable convertedPieces = pieces.map(_flattenNameNoSubdirs); return fs.path.joinAll(convertedPieces); } diff --git a/packages/flutter_tools/test/cache_test.dart b/packages/flutter_tools/test/cache_test.dart index a4ef941037..b8fe08ac5b 100644 --- a/packages/flutter_tools/test/cache_test.dart +++ b/packages/flutter_tools/test/cache_test.dart @@ -77,6 +77,14 @@ void main() { 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: { + FileSystem: () => new MockFileSystem(), + }); } class MockFileSystem extends MemoryFileSystem {