| 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 pub.system_cache; | 5 library pub.system_cache; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | 7 import 'dart:io'; |
| 9 | 8 |
| 10 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 11 | 10 |
| 12 import 'io.dart'; | 11 import 'io.dart'; |
| 13 import 'io.dart' as io show createTempDir; | 12 import 'io.dart' as io show createTempDir; |
| 14 import 'log.dart' as log; | 13 import 'log.dart' as log; |
| 15 import 'package.dart'; | 14 import 'package.dart'; |
| 16 import 'source/cached.dart'; | 15 import 'source/cached.dart'; |
| 17 import 'source/git.dart'; | 16 import 'source/git.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 /// Registers a new source. | 71 /// Registers a new source. |
| 73 /// | 72 /// |
| 74 /// This source must not have the same name as a source that's already been | 73 /// This source must not have the same name as a source that's already been |
| 75 /// registered. | 74 /// registered. |
| 76 void register(Source source) { | 75 void register(Source source) { |
| 77 source.bind(this); | 76 source.bind(this); |
| 78 sources.register(source); | 77 sources.register(source); |
| 79 } | 78 } |
| 80 | 79 |
| 81 /// Determines if the system cache contains the package identified by [id]. | 80 /// Determines if the system cache contains the package identified by [id]. |
| 82 Future<bool> contains(PackageId id) { | 81 /// |
| 82 /// Depending on the source, this may throw an [ArgumentError] if [id] isn't |
| 83 /// resolved using [Source.resolveId]. |
| 84 bool contains(PackageId id) { |
| 83 var source = sources[id.source]; | 85 var source = sources[id.source]; |
| 84 | 86 |
| 85 if (source is! CachedSource) { | 87 if (source is! CachedSource) { |
| 86 throw new ArgumentError("Package $id is not cacheable."); | 88 throw new ArgumentError("Package $id is not cacheable."); |
| 87 } | 89 } |
| 88 | 90 |
| 89 return source.isInSystemCache(id); | 91 return source.isInSystemCache(id); |
| 90 } | 92 } |
| 91 | 93 |
| 92 /// Create a new temporary directory within the system cache. | 94 /// Create a new temporary directory within the system cache. |
| 93 /// | 95 /// |
| 94 /// The system cache maintains its own temporary directory that it uses to | 96 /// The system cache maintains its own temporary directory that it uses to |
| 95 /// stage packages into while downloading. It uses this instead of the OS's | 97 /// stage packages into while downloading. It uses this instead of the OS's |
| 96 /// system temp directory to ensure that it's on the same volume as the pub | 98 /// system temp directory to ensure that it's on the same volume as the pub |
| 97 /// system cache so that it can move the directory from it. | 99 /// system cache so that it can move the directory from it. |
| 98 String createTempDir() { | 100 String createTempDir() { |
| 99 var temp = ensureDir(tempDir); | 101 var temp = ensureDir(tempDir); |
| 100 return io.createTempDir(temp, 'dir'); | 102 return io.createTempDir(temp, 'dir'); |
| 101 } | 103 } |
| 102 | 104 |
| 103 /// Deletes the system cache's internal temp directory. | 105 /// Deletes the system cache's internal temp directory. |
| 104 void deleteTempDir() { | 106 void deleteTempDir() { |
| 105 log.fine('Clean up system cache temp directory $tempDir.'); | 107 log.fine('Clean up system cache temp directory $tempDir.'); |
| 106 if (dirExists(tempDir)) deleteEntry(tempDir); | 108 if (dirExists(tempDir)) deleteEntry(tempDir); |
| 107 } | 109 } |
| 108 } | 110 } |
| OLD | NEW |