OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 system_cache; | 5 library system_cache; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 import 'git_source.dart'; | 10 import 'git_source.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 /// Registers a new source. This source must not have the same name as a | 56 /// Registers a new source. This source must not have the same name as a |
57 /// source that's already been registered. | 57 /// source that's already been registered. |
58 void register(Source source) { | 58 void register(Source source) { |
59 source.bind(this); | 59 source.bind(this); |
60 sources.register(source); | 60 sources.register(source); |
61 } | 61 } |
62 | 62 |
63 /// Gets the package identified by [id]. If the package is already cached, | 63 /// Gets the package identified by [id]. If the package is already cached, |
64 /// reads it from the cache. Otherwise, requests it from the source. | 64 /// reads it from the cache. Otherwise, requests it from the source. |
65 Future<Pubspec> describe(PackageId id) { | 65 Future<Pubspec> describe(PackageId id) { |
| 66 if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); |
| 67 |
66 // Try to get it from the system cache first. | 68 // Try to get it from the system cache first. |
67 if (id.source.shouldCache) { | 69 if (id.source.shouldCache) { |
68 return id.systemCacheDirectory.then((packageDir) { | 70 return id.systemCacheDirectory.then((packageDir) { |
69 if (!dirExists(packageDir)) return id.describe(); | 71 if (!dirExists(packageDir)) return id.describe(); |
70 return new Pubspec.load(id.name, packageDir, sources); | 72 return new Pubspec.load(id.name, packageDir, sources); |
71 }); | 73 }); |
72 } | 74 } |
73 | 75 |
74 // Not cached, so get it from the source. | 76 // Not cached, so get it from the source. |
75 return id.describe(); | 77 return id.describe(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 110 |
109 /// Delete's the system cache's internal temp directory. | 111 /// Delete's the system cache's internal temp directory. |
110 Future deleteTempDir() { | 112 Future deleteTempDir() { |
111 log.fine('Clean up system cache temp directory $tempDir.'); | 113 log.fine('Clean up system cache temp directory $tempDir.'); |
112 return defer(() { | 114 return defer(() { |
113 if (!dirExists(tempDir)) return; | 115 if (!dirExists(tempDir)) return; |
114 return deleteDir(tempDir); | 116 return deleteDir(tempDir); |
115 }); | 117 }); |
116 } | 118 } |
117 } | 119 } |
OLD | NEW |