| 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('io.dart'); | 7 #import('io.dart'); |
| 8 #import('package.dart'); | 8 #import('package.dart'); |
| 9 #import('source.dart'); | 9 #import('source.dart'); |
| 10 #import('source_registry.dart'); | 10 #import('source_registry.dart'); |
| 11 #import('utils.dart'); | 11 #import('utils.dart'); |
| 12 #import('version.dart'); |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * The system-wide cache of installed packages. | 15 * The system-wide cache of installed packages. |
| 15 * | 16 * |
| 16 * This cache contains all packages that are downloaded from the internet. | 17 * This cache contains all packages that are downloaded from the internet. |
| 17 * Packages that are available locally (e.g. from the SDK) don't use this cache. | 18 * Packages that are available locally (e.g. from the SDK) don't use this cache. |
| 18 */ | 19 */ |
| 19 class SystemCache { | 20 class SystemCache { |
| 20 /** | 21 /** |
| 21 * The root directory where this package cache is located. | 22 * The root directory where this package cache is located. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * Loads all of the package ids in the cache and returns them. | 54 * Loads all of the package ids in the cache and returns them. |
| 54 */ | 55 */ |
| 55 Future<List<PackageId>> listAll() { | 56 Future<List<PackageId>> listAll() { |
| 56 return listDir(rootDir).chain((paths) { | 57 return listDir(rootDir).chain((paths) { |
| 57 final sources = paths.map((path) { | 58 final sources = paths.map((path) { |
| 58 final source = sources[basename(path)]; | 59 final source = sources[basename(path)]; |
| 59 return listDir(path).transform((subpaths) { | 60 return listDir(path).transform((subpaths) { |
| 60 // TODO(rnystrom): Once there are cached packages and this path is | 61 // TODO(rnystrom): Once there are cached packages and this path is |
| 61 // being used, figure out how version numbers should be acquired. | 62 // being used, figure out how version numbers should be acquired. |
| 62 return subpaths.map((subpath) => | 63 return subpaths.map((subpath) => |
| 63 new PackageId(basename(subpath), source, Version.none)); | 64 new PackageId(source, Version.none, basename(subpath))); |
| 64 }); | 65 }); |
| 65 }); | 66 }); |
| 66 return Futures.wait(sources).transform(flatten); | 67 return Futures.wait(sources).transform(flatten); |
| 67 }); | 68 }); |
| 68 } | 69 } |
| 69 | 70 |
| 70 /** | 71 /** |
| 71 * Ensures that the package identified by [id] is installed to the cache, | 72 * Ensures that the package identified by [id] is installed to the cache, |
| 72 * loads it, and returns it. | 73 * loads it, and returns it. |
| 73 * | 74 * |
| 74 * It is an error to try installing a package from a source with `shouldCache | 75 * It is an error to try installing a package from a source with `shouldCache |
| 75 * == false` to the system cache. | 76 * == false` to the system cache. |
| 76 */ | 77 */ |
| 77 Future<Package> install(PackageId id) { | 78 Future<Package> install(PackageId id) { |
| 78 if (!id.source.shouldCache) { | 79 if (!id.source.shouldCache) { |
| 79 throw new IllegalArgumentException("Package $id is not cacheable."); | 80 throw new IllegalArgumentException("Package $id is not cacheable."); |
| 80 } | 81 } |
| 81 | 82 |
| 82 var pending = _pendingInstalls[id]; | 83 var pending = _pendingInstalls[id]; |
| 83 if (pending != null) return pending; | 84 if (pending != null) return pending; |
| 84 | 85 |
| 85 var future = id.source.installToSystemCache(id); | 86 var future = id.source.installToSystemCache(id); |
| 86 always(future, () => _pendingInstalls.remove(id)); | 87 always(future, () => _pendingInstalls.remove(id)); |
| 87 _pendingInstalls[id] = future; | 88 _pendingInstalls[id] = future; |
| 88 return future; | 89 return future; |
| 89 } | 90 } |
| 90 } | 91 } |
| OLD | NEW |