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'; |
| 8 |
7 import 'io.dart'; | 9 import 'io.dart'; |
| 10 import 'io.dart' as io show createTempDir; |
8 import 'package.dart'; | 11 import 'package.dart'; |
9 import 'source.dart'; | 12 import 'source.dart'; |
10 import 'source_registry.dart'; | 13 import 'source_registry.dart'; |
11 import 'utils.dart'; | 14 import 'utils.dart'; |
12 import 'version.dart'; | 15 import 'version.dart'; |
13 | 16 |
14 /** | 17 /** |
15 * The system-wide cache of installed packages. | 18 * The system-wide cache of installed packages. |
16 * | 19 * |
17 * This cache contains all packages that are downloaded from the internet. | 20 * This cache contains all packages that are downloaded from the internet. |
18 * Packages that are available locally (e.g. from the SDK) don't use this cache. | 21 * Packages that are available locally (e.g. from the SDK) don't use this cache. |
19 */ | 22 */ |
20 class SystemCache { | 23 class SystemCache { |
21 /** | 24 /** |
22 * The root directory where this package cache is located. | 25 * The root directory where this package cache is located. |
23 */ | 26 */ |
24 final String rootDir; | 27 final String rootDir; |
25 | 28 |
| 29 String get tempDir => join(rootDir, '_temp'); |
| 30 |
26 /** | 31 /** |
27 * Packages which are currently being asynchronously installed to the cache. | 32 * Packages which are currently being asynchronously installed to the cache. |
28 */ | 33 */ |
29 final Map<PackageId, Future<Package>> _pendingInstalls; | 34 final Map<PackageId, Future<Package>> _pendingInstalls; |
30 | 35 |
31 /** | 36 /** |
32 * The sources from which to install packages. | 37 * The sources from which to install packages. |
33 */ | 38 */ |
34 final SourceRegistry sources; | 39 final SourceRegistry sources; |
35 | 40 |
(...skipping 27 matching lines...) Expand all Loading... |
63 } | 68 } |
64 | 69 |
65 var pending = _pendingInstalls[id]; | 70 var pending = _pendingInstalls[id]; |
66 if (pending != null) return pending; | 71 if (pending != null) return pending; |
67 | 72 |
68 var future = id.source.installToSystemCache(id); | 73 var future = id.source.installToSystemCache(id); |
69 always(future, () => _pendingInstalls.remove(id)); | 74 always(future, () => _pendingInstalls.remove(id)); |
70 _pendingInstalls[id] = future; | 75 _pendingInstalls[id] = future; |
71 return future; | 76 return future; |
72 } | 77 } |
| 78 |
| 79 /// Create a new temporary directory within the system cache. The system |
| 80 /// cache maintains its own temporary directory that it uses to stage |
| 81 /// packages into while installing. It uses this instead of the OS's system |
| 82 /// temp directory to ensure that it's on the same volume as the pub system |
| 83 /// cache so that it can move the directory from it. |
| 84 Future<Directory> createTempDir() { |
| 85 return ensureDir(tempDir).chain((temp) { |
| 86 return io.createTempDir(join(temp, 'dir')); |
| 87 }); |
| 88 } |
| 89 |
| 90 /// Delete's the system cache's internal temp directory. |
| 91 Future deleteTempDir() { |
| 92 return dirExists(tempDir).chain((exists) { |
| 93 if (!exists) return new Future.immediate(null); |
| 94 return deleteDir(tempDir); |
| 95 }); |
| 96 } |
73 } | 97 } |
OLD | NEW |