Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: utils/pub/hosted_source.dart

Issue 12755024: add cache list command to pub (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/git_source.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,19 @@
return description;
}
+ Future<List<Package>> getCachedPackages() {
+ return defer(() {
+ var cacheDir = path.join(systemCacheRoot,
+ _getSourceDirectory(_defaultUrl));
+ if (!dirExists(cacheDir)) return [];
+
+ return listDir(path.join(cacheDir)).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 +158,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.
« no previous file with comments | « utils/pub/git_source.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698