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 'package:pathos/path.dart' as path; | 10 import 'package:pathos/path.dart' as path; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 /// Gets the package identified by [id]. If the package is already cached, | 65 /// Gets the package identified by [id]. If the package is already cached, |
66 /// reads it from the cache. Otherwise, requests it from the source. | 66 /// reads it from the cache. Otherwise, requests it from the source. |
67 Future<Pubspec> describe(PackageId id) { | 67 Future<Pubspec> describe(PackageId id) { |
68 if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); | 68 if (id.isRoot) throw new ArgumentError("Cannot describe the root package."); |
69 | 69 |
70 // Try to get it from the system cache first. | 70 // Try to get it from the system cache first. |
71 if (id.source.shouldCache) { | 71 if (id.source.shouldCache) { |
72 return id.systemCacheDirectory.then((packageDir) { | 72 return id.systemCacheDirectory.then((packageDir) { |
73 if (!dirExists(packageDir)) return id.describe(); | 73 if (!fileExists(path.join(packageDir, "pubspec.yaml"))) { |
| 74 return id.source.describe(id); |
| 75 } |
| 76 |
74 return new Pubspec.load(id.name, packageDir, sources); | 77 return new Pubspec.load(id.name, packageDir, sources); |
75 }); | 78 }); |
76 } | 79 } |
77 | 80 |
78 // Not cached, so get it from the source. | 81 // Not cached, so get it from the source. |
79 return id.describe(); | 82 return id.source.describe(id); |
80 } | 83 } |
81 | 84 |
82 /// 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, |
83 /// loads it, and returns it. | 86 /// loads it, and returns it. |
84 /// | 87 /// |
85 /// 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 |
86 /// == false` to the system cache. | 89 /// == false` to the system cache. |
87 Future<Package> install(PackageId id) { | 90 Future<Package> install(PackageId id) { |
88 if (!id.source.shouldCache) { | 91 if (!id.source.shouldCache) { |
89 throw new ArgumentError("Package $id is not cacheable."); | 92 throw new ArgumentError("Package $id is not cacheable."); |
(...skipping 17 matching lines...) Expand all Loading... |
107 var temp = ensureDir(tempDir); | 110 var temp = ensureDir(tempDir); |
108 return io.createTempDir(path.join(temp, 'dir')); | 111 return io.createTempDir(path.join(temp, 'dir')); |
109 } | 112 } |
110 | 113 |
111 /// Deletes the system cache's internal temp directory. | 114 /// Deletes the system cache's internal temp directory. |
112 void deleteTempDir() { | 115 void deleteTempDir() { |
113 log.fine('Clean up system cache temp directory $tempDir.'); | 116 log.fine('Clean up system cache temp directory $tempDir.'); |
114 if (dirExists(tempDir)) deleteEntry(tempDir); | 117 if (dirExists(tempDir)) deleteEntry(tempDir); |
115 } | 118 } |
116 } | 119 } |
OLD | NEW |