Chromium Code Reviews| 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 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'git_source.dart'; | 10 import 'git_source.dart'; |
| 11 import 'hosted_source.dart'; | 11 import 'hosted_source.dart'; |
| 12 import 'io.dart'; | 12 import 'io.dart'; |
| 13 import 'io.dart' as io show createTempDir; | 13 import 'io.dart' as io show createTempDir; |
| 14 import 'log.dart' as log; | 14 import 'log.dart' as log; |
| 15 import 'package.dart'; | 15 import 'package.dart'; |
| 16 import 'pubspec.dart'; | |
| 16 import 'sdk_source.dart'; | 17 import 'sdk_source.dart'; |
| 17 import 'source.dart'; | 18 import 'source.dart'; |
| 18 import 'source_registry.dart'; | 19 import 'source_registry.dart'; |
| 19 import 'utils.dart'; | 20 import 'utils.dart'; |
| 20 import 'version.dart'; | 21 import 'version.dart'; |
| 21 | 22 |
| 22 /// The system-wide cache of installed packages. | 23 /// The system-wide cache of installed packages. |
| 23 /// | 24 /// |
| 24 /// This cache contains all packages that are downloaded from the internet. | 25 /// This cache contains all packages that are downloaded from the internet. |
| 25 /// Packages that are available locally (e.g. from the SDK) don't use this | 26 /// Packages that are available locally (e.g. from the SDK) don't use this |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 52 return cache; | 53 return cache; |
| 53 } | 54 } |
| 54 | 55 |
| 55 /// Registers a new source. This source must not have the same name as a | 56 /// Registers a new source. This source must not have the same name as a |
| 56 /// source that's already been registered. | 57 /// source that's already been registered. |
| 57 void register(Source source) { | 58 void register(Source source) { |
| 58 source.bind(this); | 59 source.bind(this); |
| 59 sources.register(source); | 60 sources.register(source); |
| 60 } | 61 } |
| 61 | 62 |
| 63 /// Gets the package identified by [id]. If the package is already cached, | |
| 64 /// reads it from the cache. Otherwise, requests it from the source. | |
| 65 Future<Package> describe(PackageId id) { | |
|
nweiz
2013/01/31 22:38:53
I don't like that this returns a Package whereas o
Bob Nystrom
2013/02/01 16:53:29
I had that originally, but Pubspec doesn't know ho
nweiz
2013/02/01 22:24:54
I think it's fine to use Package internally to loa
Bob Nystrom
2013/02/02 00:02:31
Done.
| |
| 66 Future<Package> getUncached() { | |
| 67 // Not cached, so get it from the source. | |
| 68 return id.source.describe(id).then((pubspec) { | |
|
nweiz
2013/01/31 22:38:53
"id.source.describe(id)" -> "id.describe()"
Bob Nystrom
2013/02/01 16:53:29
Done.
| |
| 69 return new Package.inMemory(pubspec); | |
| 70 }); | |
| 71 } | |
| 72 | |
| 73 // Try to get it from the system cache first. | |
| 74 if (id.source.shouldCache) { | |
| 75 return id.source.systemCacheDirectory(id).then((packageDir) { | |
|
nweiz
2013/01/31 22:38:53
This would be a little cleaner with an "id.systemC
Bob Nystrom
2013/02/01 16:53:29
Done.
| |
| 76 if (!dirExistsSync(packageDir)) return getUncached(); | |
| 77 return Package.load(id.name, packageDir, sources); | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 // Not cached, so get it from the source. | |
| 82 return getUncached(); | |
| 83 } | |
| 84 | |
| 62 /// Ensures that the package identified by [id] is installed to the cache, | 85 /// Ensures that the package identified by [id] is installed to the cache, |
| 63 /// loads it, and returns it. | 86 /// loads it, and returns it. |
| 64 /// | 87 /// |
| 65 /// It is an error to try installing a package from a source with `shouldCache | 88 /// It is an error to try installing a package from a source with `shouldCache |
| 66 /// == false` to the system cache. | 89 /// == false` to the system cache. |
| 67 Future<Package> install(PackageId id) { | 90 Future<Package> install(PackageId id) { |
| 68 if (!id.source.shouldCache) { | 91 if (!id.source.shouldCache) { |
| 69 throw new ArgumentError("Package $id is not cacheable."); | 92 throw new ArgumentError("Package $id is not cacheable."); |
| 70 } | 93 } |
| 71 | 94 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 91 | 114 |
| 92 /// Delete's the system cache's internal temp directory. | 115 /// Delete's the system cache's internal temp directory. |
| 93 Future deleteTempDir() { | 116 Future deleteTempDir() { |
| 94 log.fine('Clean up system cache temp directory $tempDir.'); | 117 log.fine('Clean up system cache temp directory $tempDir.'); |
| 95 return dirExists(tempDir).then((exists) { | 118 return dirExists(tempDir).then((exists) { |
| 96 if (!exists) return; | 119 if (!exists) return; |
| 97 return deleteDir(tempDir); | 120 return deleteDir(tempDir); |
| 98 }); | 121 }); |
| 99 } | 122 } |
| 100 } | 123 } |
| OLD | NEW |