| 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('package.dart'); | 7 #import('package.dart'); |
| 8 #import('source_registry.dart'); | 8 #import('source_registry.dart'); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 * == false` to the system cache. | 63 * == false` to the system cache. |
| 64 */ | 64 */ |
| 65 Future<Package> install(PackageId id) { | 65 Future<Package> install(PackageId id) { |
| 66 if (!id.source.shouldCache) { | 66 if (!id.source.shouldCache) { |
| 67 throw new IllegalArgumentException("Package $id is not cacheable."); | 67 throw new IllegalArgumentException("Package $id is not cacheable."); |
| 68 } | 68 } |
| 69 | 69 |
| 70 var pending = _pendingInstalls[id]; | 70 var pending = _pendingInstalls[id]; |
| 71 if (pending != null) return pending; | 71 if (pending != null) return pending; |
| 72 | 72 |
| 73 var path = join(rootDir, id.source.name, id.source.packageName(id)); | 73 var sourceDir = join(rootDir, id.source.name); |
| 74 var path = id.source.systemCacheDirectory(id, sourceDir); |
| 74 var future = exists(path).chain((exists) { | 75 var future = exists(path).chain((exists) { |
| 75 // TODO(nweiz): better error handling | 76 // TODO(nweiz): better error handling |
| 76 if (exists) throw 'Package $id is already installed.'; | 77 if (exists) throw 'Package $id is already installed.'; |
| 77 return ensureDir(dirname(path)); | 78 return ensureDir(dirname(path)); |
| 78 }).chain((_) { | 79 }).chain((_) { |
| 79 return id.source.install(id, path); | 80 return id.source.install(id, path); |
| 80 }).chain((found) { | 81 }).chain((found) { |
| 81 if (!found) { | 82 if (!found) { |
| 82 throw 'Package ${id.fullName} not found in source "${id.source.name}".'; | 83 throw 'Package ${id.fullName} not found in source "${id.source.name}".'; |
| 83 } | 84 } |
| 84 return Package.load(path, sources); | 85 return Package.load(path, sources); |
| 85 }); | 86 }); |
| 86 | 87 |
| 87 always(future, () => _pendingInstalls.remove(id)); | 88 always(future, () => _pendingInstalls.remove(id)); |
| 88 _pendingInstalls[id] = future; | 89 _pendingInstalls[id] = future; |
| 89 return future; | 90 return future; |
| 90 } | 91 } |
| 91 } | 92 } |
| OLD | NEW |