| 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'); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 * == false` to the system cache. | 75 * == false` to the system cache. |
| 76 */ | 76 */ |
| 77 Future<Package> install(PackageId id) { | 77 Future<Package> install(PackageId id) { |
| 78 if (!id.source.shouldCache) { | 78 if (!id.source.shouldCache) { |
| 79 throw new IllegalArgumentException("Package $id is not cacheable."); | 79 throw new IllegalArgumentException("Package $id is not cacheable."); |
| 80 } | 80 } |
| 81 | 81 |
| 82 var pending = _pendingInstalls[id]; | 82 var pending = _pendingInstalls[id]; |
| 83 if (pending != null) return pending; | 83 if (pending != null) return pending; |
| 84 | 84 |
| 85 var future = id.source.installToSystemCache(id); | 85 var path = id.source.systemCacheDirectory(id); |
| 86 var future = exists(path).chain((exists) { |
| 87 // TODO(nweiz): better error handling |
| 88 if (exists) throw 'Package $id is already installed.'; |
| 89 return ensureDir(dirname(path)); |
| 90 }).chain((_) { |
| 91 return id.source.install(id, path); |
| 92 }).chain((found) { |
| 93 if (!found) throw 'Package $id not found.'; |
| 94 return Package.load(path, sources); |
| 95 }); |
| 96 |
| 86 always(future, () => _pendingInstalls.remove(id)); | 97 always(future, () => _pendingInstalls.remove(id)); |
| 87 _pendingInstalls[id] = future; | 98 _pendingInstalls[id] = future; |
| 88 return future; | 99 return future; |
| 89 } | 100 } |
| 90 } | 101 } |
| OLD | NEW |