| 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'; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 /// reads it from the cache. Otherwise, requests it from the source. | 64 /// reads it from the cache. Otherwise, requests it from the source. |
| 65 Future<Package> describe(PackageId id) { | 65 Future<Package> describe(PackageId id) { |
| 66 Future<Package> getUncached() { | 66 Future<Package> getUncached() { |
| 67 // Not cached, so get it from the source. | 67 // Not cached, so get it from the source. |
| 68 return id.describe().then((pubspec) => new Package.inMemory(pubspec)); | 68 return id.describe().then((pubspec) => new Package.inMemory(pubspec)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Try to get it from the system cache first. | 71 // Try to get it from the system cache first. |
| 72 if (id.source.shouldCache) { | 72 if (id.source.shouldCache) { |
| 73 return id.systemCacheDirectory.then((packageDir) { | 73 return id.systemCacheDirectory.then((packageDir) { |
| 74 if (!dirExistsSync(packageDir)) return getUncached(); | 74 if (!dirExists(packageDir)) return getUncached(); |
| 75 return Package.load(id.name, packageDir, sources); | 75 return new Package(id.name, packageDir, sources); |
| 76 }); | 76 }); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Not cached, so get it from the source. | 79 // Not cached, so get it from the source. |
| 80 return getUncached(); | 80 return getUncached(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 /// Ensures that the package identified by [id] is installed to the cache, | 83 /// Ensures that the package identified by [id] is installed to the cache, |
| 84 /// loads it, and returns it. | 84 /// loads it, and returns it. |
| 85 /// | 85 /// |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 _pendingInstalls[id] = future; | 98 _pendingInstalls[id] = future; |
| 99 return future; | 99 return future; |
| 100 } | 100 } |
| 101 | 101 |
| 102 /// Create a new temporary directory within the system cache. The system | 102 /// Create a new temporary directory within the system cache. The system |
| 103 /// cache maintains its own temporary directory that it uses to stage | 103 /// cache maintains its own temporary directory that it uses to stage |
| 104 /// packages into while installing. It uses this instead of the OS's system | 104 /// packages into while installing. It uses this instead of the OS's system |
| 105 /// temp directory to ensure that it's on the same volume as the pub system | 105 /// temp directory to ensure that it's on the same volume as the pub system |
| 106 /// cache so that it can move the directory from it. | 106 /// cache so that it can move the directory from it. |
| 107 Future<Directory> createTempDir() { | 107 Future<Directory> createTempDir() { |
| 108 return ensureDir(tempDir).then((temp) { | 108 return defer(() { |
| 109 var temp = ensureDir(tempDir); |
| 109 return io.createTempDir(join(temp, 'dir')); | 110 return io.createTempDir(join(temp, 'dir')); |
| 110 }); | 111 }); |
| 111 } | 112 } |
| 112 | 113 |
| 113 /// Delete's the system cache's internal temp directory. | 114 /// Delete's the system cache's internal temp directory. |
| 114 Future deleteTempDir() { | 115 Future deleteTempDir() { |
| 115 log.fine('Clean up system cache temp directory $tempDir.'); | 116 log.fine('Clean up system cache temp directory $tempDir.'); |
| 116 return dirExists(tempDir).then((exists) { | 117 return defer(() { |
| 117 if (!exists) return; | 118 if (!dirExists(tempDir)) return; |
| 118 return deleteDir(tempDir); | 119 return deleteDir(tempDir); |
| 119 }); | 120 }); |
| 120 } | 121 } |
| 121 } | 122 } |
| OLD | NEW |