| 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
| 8 | 8 |
| 9 import 'io.dart'; | 9 import 'io.dart'; |
| 10 import 'io.dart' as io show createTempDir; | 10 import 'io.dart' as io show createTempDir; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 return new Package.load( | 96 return new Package.load( |
| 97 id.name, source(id.source).getDirectory(id), sources); | 97 id.name, source(id.source).getDirectory(id), sources); |
| 98 } | 98 } |
| 99 | 99 |
| 100 /// Determines if the system cache contains the package identified by [id]. | 100 /// Determines if the system cache contains the package identified by [id]. |
| 101 bool contains(PackageId id) { | 101 bool contains(PackageId id) { |
| 102 var source = this.source(id.source); | 102 var source = this.source(id.source); |
| 103 | 103 |
| 104 if (source is! CachedSource) { | 104 if (source is CachedSource) return source.isInSystemCache(id); |
| 105 throw new ArgumentError("Package $id is not cacheable."); | 105 throw new ArgumentError("Package $id is not cacheable."); |
| 106 } | |
| 107 | |
| 108 return source.isInSystemCache(id); | |
| 109 } | 106 } |
| 110 | 107 |
| 111 /// Create a new temporary directory within the system cache. | 108 /// Create a new temporary directory within the system cache. |
| 112 /// | 109 /// |
| 113 /// The system cache maintains its own temporary directory that it uses to | 110 /// The system cache maintains its own temporary directory that it uses to |
| 114 /// stage packages into while downloading. It uses this instead of the OS's | 111 /// stage packages into while downloading. It uses this instead of the OS's |
| 115 /// system temp directory to ensure that it's on the same volume as the pub | 112 /// system temp directory to ensure that it's on the same volume as the pub |
| 116 /// system cache so that it can move the directory from it. | 113 /// system cache so that it can move the directory from it. |
| 117 String createTempDir() { | 114 String createTempDir() { |
| 118 var temp = ensureDir(tempDir); | 115 var temp = ensureDir(tempDir); |
| 119 return io.createTempDir(temp, 'dir'); | 116 return io.createTempDir(temp, 'dir'); |
| 120 } | 117 } |
| 121 | 118 |
| 122 /// Deletes the system cache's internal temp directory. | 119 /// Deletes the system cache's internal temp directory. |
| 123 void deleteTempDir() { | 120 void deleteTempDir() { |
| 124 log.fine('Clean up system cache temp directory $tempDir.'); | 121 log.fine('Clean up system cache temp directory $tempDir.'); |
| 125 if (dirExists(tempDir)) deleteEntry(tempDir); | 122 if (dirExists(tempDir)) deleteEntry(tempDir); |
| 126 } | 123 } |
| 127 } | 124 } |
| OLD | NEW |