OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub.source.cached; | 5 library pub.source.cached; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 abstract class CachedSource extends Source { | 23 abstract class CachedSource extends Source { |
24 /// The root directory of this source's cache within the system cache. | 24 /// The root directory of this source's cache within the system cache. |
25 /// | 25 /// |
26 /// This shouldn't be overridden by subclasses. | 26 /// This shouldn't be overridden by subclasses. |
27 String get systemCacheRoot => path.join(systemCache.rootDir, name); | 27 String get systemCacheRoot => path.join(systemCache.rootDir, name); |
28 | 28 |
29 /// If [id] is already in the system cache, just loads it from there. | 29 /// If [id] is already in the system cache, just loads it from there. |
30 /// | 30 /// |
31 /// Otherwise, defers to the subclass. | 31 /// Otherwise, defers to the subclass. |
32 Future<Pubspec> doDescribe(PackageId id) async { | 32 Future<Pubspec> doDescribe(PackageId id) async { |
33 var packageDir = getDirectory(await resolveId(id)); | 33 var packageDir = getDirectory(id); |
34 if (fileExists(path.join(packageDir, "pubspec.yaml"))) { | 34 if (fileExists(path.join(packageDir, "pubspec.yaml"))) { |
35 return new Pubspec.load(packageDir, systemCache.sources, | 35 return new Pubspec.load(packageDir, systemCache.sources, |
36 expectedName: id.name); | 36 expectedName: id.name); |
37 } | 37 } |
38 | 38 |
39 return await describeUncached(id); | 39 return await describeUncached(id); |
40 } | 40 } |
41 | 41 |
42 /// Loads the (possibly remote) pubspec for the package version identified by | 42 /// Loads the (possibly remote) pubspec for the package version identified by |
43 /// [id]. | 43 /// [id]. |
44 /// | 44 /// |
45 /// This will only be called for packages that have not yet been installed in | 45 /// This will only be called for packages that have not yet been installed in |
46 /// the system cache. | 46 /// the system cache. |
47 Future<Pubspec> describeUncached(PackageId id); | 47 Future<Pubspec> describeUncached(PackageId id); |
48 | 48 |
49 Future get(PackageId id, String symlink) { | 49 Future get(PackageId id, String symlink) { |
50 return downloadToSystemCache(id).then((pkg) { | 50 return downloadToSystemCache(id).then((pkg) { |
51 createPackageSymlink(id.name, pkg.dir, symlink); | 51 createPackageSymlink(id.name, pkg.dir, symlink); |
52 }); | 52 }); |
53 } | 53 } |
54 | 54 |
55 /// Determines if the package with [id] is already downloaded to the system | 55 /// Determines if the package identified by [id] is already downloaded to the |
56 /// cache. | 56 /// system cache. |
57 /// | |
58 /// Depending on the source, this may throw an [ArgumentError] if [id] isn't | |
59 /// resolved using [resolveId]. | |
60 bool isInSystemCache(PackageId id) => dirExists(getDirectory(id)); | 57 bool isInSystemCache(PackageId id) => dirExists(getDirectory(id)); |
61 | 58 |
62 /// Downloads the package identified by [id] to the system cache. | 59 /// Downloads the package identified by [id] to the system cache. |
63 Future<Package> downloadToSystemCache(PackageId id); | 60 Future<Package> downloadToSystemCache(PackageId id); |
64 | 61 |
65 /// Returns the [Package]s that have been downloaded to the system cache. | 62 /// Returns the [Package]s that have been downloaded to the system cache. |
66 List<Package> getCachedPackages(); | 63 List<Package> getCachedPackages(); |
67 | 64 |
68 /// Reinstalls all packages that have been previously installed into the | 65 /// Reinstalls all packages that have been previously installed into the |
69 /// system cache by this source. | 66 /// system cache by this source. |
70 /// | 67 /// |
71 /// Returns a [Pair] whose first element is the packages that were | 68 /// Returns a [Pair] whose first element is the packages that were |
72 /// successfully repaired and the second is the packages that failed to be | 69 /// successfully repaired and the second is the packages that failed to be |
73 /// repaired. | 70 /// repaired. |
74 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages(); | 71 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages(); |
75 } | 72 } |
OLD | NEW |