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

Unified Diff: sdk/lib/_internal/pub/lib/src/source/hosted.dart

Issue 243683002: Refactor Source. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise all the things. Created 6 years, 8 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 | « sdk/lib/_internal/pub/lib/src/source/git.dart ('k') | sdk/lib/_internal/pub/lib/src/source/path.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/source/hosted.dart
diff --git a/sdk/lib/_internal/pub/lib/src/source/hosted.dart b/sdk/lib/_internal/pub/lib/src/source/hosted.dart
index dd5cb0faad15e47b7087ad32264dff4696fea6ef..b42ba77f823337ffdfe6d885f9a18feafc26c892 100644
--- a/sdk/lib/_internal/pub/lib/src/source/hosted.dart
+++ b/sdk/lib/_internal/pub/lib/src/source/hosted.dart
@@ -16,16 +16,14 @@ import '../io.dart';
import '../log.dart' as log;
import '../package.dart';
import '../pubspec.dart';
-import '../source.dart';
import '../utils.dart';
import '../version.dart';
+import 'cached.dart';
/// A package source that gets packages from a package hosting site that uses
/// the same API as pub.dartlang.org.
-class HostedSource extends Source {
-
+class HostedSource extends CachedSource {
final name = "hosted";
- final shouldCache = true;
/// Gets the default URL for the package server for hosted dependencies.
static String get defaultUrl {
@@ -76,17 +74,39 @@ class HostedSource extends Source {
});
}
- /// Downloads a package from the site and unpacks it.
- Future<bool> get(PackageId id, String destPath) {
- var parsed = _parseDescription(id.description);
- return _download(parsed.last, parsed.first, id.version, destPath);
+ /// Downloads the package identified by [id] to the system cache.
+ Future<Package> downloadToSystemCache(PackageId id) {
+ var packageDir;
+ return getDirectory(id).then((p) {
+ packageDir = p;
+
+ // See if it's already cached.
+ if (dirExists(packageDir)) {
+ if (isCachedPackageCorrupted(packageDir)) {
+ // Wipe it out and re-install it.
+ deleteEntry(packageDir);
+ } else {
+ // Already downloaded.
+ return true;
+ }
+ }
+
+ ensureDir(path.dirname(packageDir));
+
+ var parsed = _parseDescription(id.description);
+ return _download(parsed.last, parsed.first, id.version, packageDir);
+ }).then((found) {
+ if (!found) fail('Package $id not found.');
+ return new Package.load(id.name, packageDir, systemCache.sources);
+ });
}
/// The system cache directory for the hosted source contains subdirectories
- /// for each separate repository URL that's used on the system. Each of these
- /// subdirectories then contains a subdirectory for each package downloaded
- /// from that site.
- Future<String> systemCacheDirectory(PackageId id) {
+ /// for each separate repository URL that's used on the system.
+ ///
+ /// Each of these subdirectories then contains a subdirectory for each
+ /// package downloaded from that site.
+ Future<String> getDirectory(PackageId id) {
var parsed = _parseDescription(id.description);
var dir = _urlToDirectory(parsed.last);
@@ -184,6 +204,7 @@ class HostedSource extends Source {
});
});
}
+
/// 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.
@@ -233,16 +254,18 @@ class OfflineHostedSource extends HostedSource {
});
}
- Future<bool> get(PackageId id, String destPath) {
- // Since HostedSource returns `true` for [shouldCache], install will only
- // be called for uncached packages.
- throw new UnsupportedError("Cannot get packages when offline.");
+ Future<bool> _download(String server, String package, Version version,
+ String destPath) {
+ // Since HostedSource is cached, this will only be called for uncached
+ // packages.
+ throw new UnsupportedError("Cannot download packages when offline.");
}
- Future<Pubspec> describeUncached(PackageId id) {
+ Future<Pubspec> onDescribeUncached(PackageId id) {
// [getVersions()] will only return packages that are already cached.
- // Source should only call [describeUncached()] on a package after it has
- // failed to find it in the cache, so this code should not be reached.
+ // [CachedSource] will only call [onDescribeUncached()] on a package after
+ // it has failed to find it in the cache, so this code should not be
+ // reached.
throw new UnsupportedError("Cannot describe packages when offline.");
}
}
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source/git.dart ('k') | sdk/lib/_internal/pub/lib/src/source/path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698