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