Chromium Code Reviews| Index: utils/pub/hosted_source.dart |
| =================================================================== |
| --- utils/pub/hosted_source.dart (revision 19938) |
| +++ utils/pub/hosted_source.dart (working copy) |
| @@ -93,7 +93,7 @@ |
| /// from that site. |
| Future<String> systemCacheDirectory(PackageId id) { |
| var parsed = _parseDescription(id.description); |
| - var url = parsed.last.replaceAll(new RegExp(r"^https?://"), ""); |
| + var url = _getSourceDirectory(parsed.last); |
| var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { |
| return '%${match[0].codeUnitAt(0)}'; |
| }); |
| @@ -118,6 +118,17 @@ |
| return description; |
| } |
| + Future<List<Package>> getCachedPackages() { |
|
Bob Nystrom
2013/03/13 21:10:43
Since this method returns a future but internally
keertip
2013/03/13 21:36:15
Done.
|
| + var url = path.join(systemCacheRoot, _getSourceDirectory(_defaultUrl)); |
|
Bob Nystrom
2013/03/13 21:10:43
This isn't a url. How about "url" -> "cacheDir".
keertip
2013/03/13 21:36:15
Done.
|
| + if (!dirExists(url)) |
| + return new Future.immediate([]); |
|
Bob Nystrom
2013/03/13 21:10:43
Either put this on the same line as the if, or use
keertip
2013/03/13 21:36:15
Done.
|
| + |
| + return listDir(path.join(url)).then((entries) { |
| + return entries.map((entry) => |
| + new Package.load(null, entry, systemCache.sources)); |
| + }); |
| + } |
| + |
| /// When an error occurs trying to read something about [package] from [url], |
| /// this tries to translate into a more user friendly error message. Always |
| /// throws an error, either the original one or a better one. |
| @@ -145,6 +156,10 @@ |
| /// The URL of the default package repository. |
| final _defaultUrl = "https://pub.dartlang.org"; |
| +String _getSourceDirectory(String url) { |
| + return url.replaceAll(new RegExp(r"^https?://"), ""); |
| +} |
| + |
| /// Parses [description] into its server and package name components, then |
| /// converts that to a Uri given [pattern]. Ensures the package name is |
| /// properly URL encoded. |