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

Side by Side Diff: lib/src/source/cached.dart

Issue 1276673006: Make Source.getDirectory synchronous. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « lib/src/source.dart ('k') | lib/src/source/git.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 /// the same repo over time may yield different commits.) 22 /// the same repo over time may yield different commits.)
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) { 32 Future<Pubspec> doDescribe(PackageId id) async {
33 return getDirectory(id).then((packageDir) { 33 var packageDir = getDirectory(await resolveId(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 describeUncached(id); 39 return await describeUncached(id);
40 });
41 } 40 }
42 41
43 /// Loads the (possibly remote) pubspec for the package version identified by 42 /// Loads the (possibly remote) pubspec for the package version identified by
44 /// [id]. 43 /// [id].
45 /// 44 ///
46 /// 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
47 /// the system cache. 46 /// the system cache.
48 Future<Pubspec> describeUncached(PackageId id); 47 Future<Pubspec> describeUncached(PackageId id);
49 48
50 Future get(PackageId id, String symlink) { 49 Future get(PackageId id, String symlink) {
51 return downloadToSystemCache(id).then((pkg) { 50 return downloadToSystemCache(id).then((pkg) {
52 createPackageSymlink(id.name, pkg.dir, symlink); 51 createPackageSymlink(id.name, pkg.dir, symlink);
53 }); 52 });
54 } 53 }
55 54
56 /// Determines if the package with [id] is already downloaded to the system 55 /// Determines if the package with [id] is already downloaded to the system
57 /// cache. 56 /// cache.
58 Future<bool> isInSystemCache(PackageId id) => 57 ///
59 getDirectory(id).then(dirExists); 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));
60 61
61 /// Downloads the package identified by [id] to the system cache. 62 /// Downloads the package identified by [id] to the system cache.
62 Future<Package> downloadToSystemCache(PackageId id); 63 Future<Package> downloadToSystemCache(PackageId id);
63 64
64 /// Returns the [Package]s that have been downloaded to the system cache. 65 /// Returns the [Package]s that have been downloaded to the system cache.
65 List<Package> getCachedPackages(); 66 List<Package> getCachedPackages();
66 67
67 /// Reinstalls all packages that have been previously installed into the 68 /// Reinstalls all packages that have been previously installed into the
68 /// system cache by this source. 69 /// system cache by this source.
69 /// 70 ///
70 /// Returns a [Pair] whose first element is the packages that were 71 /// Returns a [Pair] whose first element is the packages that were
71 /// successfully repaired and the second is the packages that failed to be 72 /// successfully repaired and the second is the packages that failed to be
72 /// repaired. 73 /// repaired.
73 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages(); 74 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages();
74 } 75 }
OLDNEW
« no previous file with comments | « lib/src/source.dart ('k') | lib/src/source/git.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698