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 source; | 5 library source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'io.dart'; | 8 import 'io.dart'; |
9 import 'package.dart'; | 9 import 'package.dart'; |
10 import 'pubspec.dart'; | 10 import 'pubspec.dart'; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 } | 101 } |
102 | 102 |
103 /// Installs the package identified by [id] to the system cache. This is only | 103 /// Installs the package identified by [id] to the system cache. This is only |
104 /// called for sources with [shouldCache] set to true. | 104 /// called for sources with [shouldCache] set to true. |
105 /// | 105 /// |
106 /// By default, this uses [systemCacheDirectory] and [install]. | 106 /// By default, this uses [systemCacheDirectory] and [install]. |
107 Future<Package> installToSystemCache(PackageId id) { | 107 Future<Package> installToSystemCache(PackageId id) { |
108 var path; | 108 var path; |
109 return systemCacheDirectory(id).then((p) { | 109 return systemCacheDirectory(id).then((p) { |
110 path = p; | 110 path = p; |
111 if (dirExists(path)) return true; | 111 |
112 // See if it's already cached. | |
113 if (!dirExists(path)) return false; | |
114 | |
115 // Heuristic to make sure the cached package didn't get deleted | |
116 // somehow. If the directory is here but there's no pubspec, assume we | |
117 // got borked and reinstall. | |
nweiz
2013/02/13 00:19:21
What if just "lib" or the contents of "lib" got wi
Bob Nystrom
2013/02/13 01:27:11
Oh, great call. Duh.
Fixed this to look for an em
nweiz
2013/02/13 02:02:05
I feel like having the pubspec check as well is st
Bob Nystrom
2013/02/13 18:00:26
Done.
| |
118 if (fileExists(join(path, 'pubspec.yaml'))) return true; | |
119 | |
120 // No pubspec, so wipe it out and reinstall. | |
121 return deleteDir(path).then((_) => false); | |
122 }).then((isInstalled) { | |
123 if (isInstalled) return true; | |
112 ensureDir(dirname(path)); | 124 ensureDir(dirname(path)); |
113 return install(id, path); | 125 return install(id, path); |
114 }).then((found) { | 126 }).then((found) { |
115 if (!found) throw 'Package $id not found.'; | 127 if (!found) throw 'Package $id not found.'; |
116 return new Package.load(id.name, path, systemCache.sources); | 128 return new Package.load(id.name, path, systemCache.sources); |
117 }); | 129 }); |
118 } | 130 } |
119 | 131 |
120 /// Returns the directory in the system cache that the package identified by | 132 /// Returns the directory in the system cache that the package identified by |
121 /// [id] should be installed to. This should return a path to a subdirectory | 133 /// [id] should be installed to. This should return a path to a subdirectory |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 /// according to [validateDescription], although it must still be serializable | 175 /// according to [validateDescription], although it must still be serializable |
164 /// to JSON and YAML. It must also be equal to [id] according to | 176 /// to JSON and YAML. It must also be equal to [id] according to |
165 /// [descriptionsEqual]. | 177 /// [descriptionsEqual]. |
166 /// | 178 /// |
167 /// By default, this just returns [id]. | 179 /// By default, this just returns [id]. |
168 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); | 180 Future<PackageId> resolveId(PackageId id) => new Future.immediate(id); |
169 | 181 |
170 /// Returns the source's name. | 182 /// Returns the source's name. |
171 String toString() => name; | 183 String toString() => name; |
172 } | 184 } |
OLD | NEW |