| 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'); | |
| 8 #import('package.dart'); | 7 #import('package.dart'); |
| 9 #import('source_registry.dart'); | 8 #import('source_registry.dart'); |
| 10 #import('utils.dart'); | |
| 11 | 9 |
| 12 /** | 10 /** |
| 13 * The system-wide cache of installed packages. | 11 * The system-wide cache of installed packages. |
| 14 * | 12 * |
| 15 * This cache contains all packages that are downloaded from the internet. | 13 * This cache contains all packages that are downloaded from the internet. |
| 16 * Packages that are available locally (e.g. from the SDK) don't use this cache. | 14 * Packages that are available locally (e.g. from the SDK) don't use this cache. |
| 17 */ | 15 */ |
| 18 class SystemCache { | 16 class SystemCache { |
| 19 /** | 17 /** |
| 20 * The root directory where this package cache is located. | 18 * The root directory where this package cache is located. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 72 |
| 75 var sourceDir = join(rootDir, id.source.name); | 73 var sourceDir = join(rootDir, id.source.name); |
| 76 var path = id.source.systemCacheDirectory(id, sourceDir); | 74 var path = id.source.systemCacheDirectory(id, sourceDir); |
| 77 var future = exists(path).chain((exists) { | 75 var future = exists(path).chain((exists) { |
| 78 // TODO(nweiz): better error handling | 76 // TODO(nweiz): better error handling |
| 79 if (exists) throw 'Package $id is already installed.'; | 77 if (exists) throw 'Package $id is already installed.'; |
| 80 return ensureDir(dirname(path)); | 78 return ensureDir(dirname(path)); |
| 81 }).chain((_) { | 79 }).chain((_) { |
| 82 return id.source.install(id, path); | 80 return id.source.install(id, path); |
| 83 }).chain((found) { | 81 }).chain((found) { |
| 84 if (!found) throw 'Package $id not found.'; | 82 if (!found) { |
| 83 throw 'Package ${id.fullName} not found in source "${id.source.name}".'; |
| 84 } |
| 85 return Package.load(path, sources); | 85 return Package.load(path, sources); |
| 86 }); | 86 }); |
| 87 | 87 |
| 88 always(future, () => _pendingInstalls.remove(id)); | 88 always(future, () => _pendingInstalls.remove(id)); |
| 89 _pendingInstalls[id] = future; | 89 _pendingInstalls[id] = future; |
| 90 return future; | 90 return future; |
| 91 } | 91 } |
| 92 } | 92 } |
| OLD | NEW |