Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: utils/pub/system_cache.dart

Issue 12092080: Validate packages against their SDK constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
11 import 'hosted_source.dart'; 11 import 'hosted_source.dart';
12 import 'io.dart'; 12 import 'io.dart';
13 import 'io.dart' as io show createTempDir; 13 import 'io.dart' as io show createTempDir;
14 import 'log.dart' as log; 14 import 'log.dart' as log;
15 import 'package.dart'; 15 import 'package.dart';
16 import 'pubspec.dart';
16 import 'sdk_source.dart'; 17 import 'sdk_source.dart';
17 import 'source.dart'; 18 import 'source.dart';
18 import 'source_registry.dart'; 19 import 'source_registry.dart';
19 import 'utils.dart'; 20 import 'utils.dart';
20 import 'version.dart'; 21 import 'version.dart';
21 22
22 /// The system-wide cache of installed packages. 23 /// The system-wide cache of installed packages.
23 /// 24 ///
24 /// This cache contains all packages that are downloaded from the internet. 25 /// This cache contains all packages that are downloaded from the internet.
25 /// Packages that are available locally (e.g. from the SDK) don't use this 26 /// Packages that are available locally (e.g. from the SDK) don't use this
(...skipping 26 matching lines...) Expand all
52 return cache; 53 return cache;
53 } 54 }
54 55
55 /// Registers a new source. This source must not have the same name as a 56 /// Registers a new source. This source must not have the same name as a
56 /// source that's already been registered. 57 /// source that's already been registered.
57 void register(Source source) { 58 void register(Source source) {
58 source.bind(this); 59 source.bind(this);
59 sources.register(source); 60 sources.register(source);
60 } 61 }
61 62
63 /// Gets the package identified by [id]. If the package is already cached,
64 /// reads it from the cache. Otherwise, requests it from the source.
65 Future<Package> describe(PackageId id) {
66 Future<Package> getUncached() {
67 // Not cached, so get it from the source.
68 return id.describe().then((pubspec) => new Package.inMemory(pubspec));
69 }
70
71 // Try to get it from the system cache first.
72 if (id.source.shouldCache) {
73 return id.systemCacheDirectory.then((packageDir) {
74 if (!dirExistsSync(packageDir)) return getUncached();
75 return Package.load(id.name, packageDir, sources);
76 });
77 }
78
79 // Not cached, so get it from the source.
80 return getUncached();
81 }
82
62 /// 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,
63 /// loads it, and returns it. 84 /// loads it, and returns it.
64 /// 85 ///
65 /// It is an error to try installing a package from a source with `shouldCache 86 /// It is an error to try installing a package from a source with `shouldCache
66 /// == false` to the system cache. 87 /// == false` to the system cache.
67 Future<Package> install(PackageId id) { 88 Future<Package> install(PackageId id) {
68 if (!id.source.shouldCache) { 89 if (!id.source.shouldCache) {
69 throw new ArgumentError("Package $id is not cacheable."); 90 throw new ArgumentError("Package $id is not cacheable.");
70 } 91 }
71 92
(...skipping 19 matching lines...) Expand all
91 112
92 /// Delete's the system cache's internal temp directory. 113 /// Delete's the system cache's internal temp directory.
93 Future deleteTempDir() { 114 Future deleteTempDir() {
94 log.fine('Clean up system cache temp directory $tempDir.'); 115 log.fine('Clean up system cache temp directory $tempDir.');
95 return dirExists(tempDir).then((exists) { 116 return dirExists(tempDir).then((exists) {
96 if (!exists) return; 117 if (!exists) return;
97 return deleteDir(tempDir); 118 return deleteDir(tempDir);
98 }); 119 });
99 } 120 }
100 } 121 }
OLDNEW
« no previous file with comments | « utils/pub/source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698