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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/source/cached.dart

Issue 1165473002: Start pulling pub from its own repo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Code review changes Created 5 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library pub.source.cached;
6
7 import 'dart:async';
8
9 import 'package:path/path.dart' as path;
10
11 import '../io.dart';
12 import '../package.dart';
13 import '../pubspec.dart';
14 import '../source.dart';
15 import '../utils.dart';
16
17 /// Base class for a [Source] that installs packages into pub's [SystemCache].
18 ///
19 /// A source should be cached if it requires network access to retrieve
20 /// packages or the package needs to be "frozen" at the point in time that it's
21 /// installed. (For example, Git packages are cached because installing from
22 /// the same repo over time may yield different commits.)
23 abstract class CachedSource extends Source {
24 /// The root directory of this source's cache within the system cache.
25 ///
26 /// This shouldn't be overridden by subclasses.
27 String get systemCacheRoot => path.join(systemCache.rootDir, name);
28
29 /// If [id] is already in the system cache, just loads it from there.
30 ///
31 /// Otherwise, defers to the subclass.
32 Future<Pubspec> doDescribe(PackageId id) {
33 return getDirectory(id).then((packageDir) {
34 if (fileExists(path.join(packageDir, "pubspec.yaml"))) {
35 return new Pubspec.load(packageDir, systemCache.sources,
36 expectedName: id.name);
37 }
38
39 return describeUncached(id);
40 });
41 }
42
43 /// Loads the (possibly remote) pubspec for the package version identified by
44 /// [id].
45 ///
46 /// This will only be called for packages that have not yet been installed in
47 /// the system cache.
48 Future<Pubspec> describeUncached(PackageId id);
49
50 Future get(PackageId id, String symlink) {
51 return downloadToSystemCache(id).then((pkg) {
52 createPackageSymlink(id.name, pkg.dir, symlink);
53 });
54 }
55
56 /// Determines if the package with [id] is already downloaded to the system
57 /// cache.
58 Future<bool> isInSystemCache(PackageId id) =>
59 getDirectory(id).then(dirExists);
60
61 /// Downloads the package identified by [id] to the system cache.
62 Future<Package> downloadToSystemCache(PackageId id);
63
64 /// Returns the [Package]s that have been downloaded to the system cache.
65 List<Package> getCachedPackages();
66
67 /// Reinstalls all packages that have been previously installed into the
68 /// system cache by this source.
69 ///
70 /// Returns a [Pair] whose first element is the number of packages
71 /// successfully repaired and the second is the number of failures.
72 Future<Pair<int, int>> repairCachedPackages();
73 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source.dart ('k') | sdk/lib/_internal/pub/lib/src/source/git.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698