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.source.hosted; | 5 library pub.source.hosted; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
9 import "dart:convert"; | 9 import "dart:convert"; |
10 | 10 |
(...skipping 65 matching lines...) Loading... |
76 _throwFriendlyError(error, stackTrace, id.name, parsed.last); | 76 _throwFriendlyError(error, stackTrace, id.name, parsed.last); |
77 } | 77 } |
78 | 78 |
79 return new Pubspec.fromMap( | 79 return new Pubspec.fromMap( |
80 version['pubspec'], systemCache.sources, | 80 version['pubspec'], systemCache.sources, |
81 expectedName: id.name, location: url); | 81 expectedName: id.name, location: url); |
82 } | 82 } |
83 | 83 |
84 /// Downloads the package identified by [id] to the system cache. | 84 /// Downloads the package identified by [id] to the system cache. |
85 Future<Package> downloadToSystemCache(PackageId id) async { | 85 Future<Package> downloadToSystemCache(PackageId id) async { |
86 if (!(await isInSystemCache(id))) { | 86 if (!isInSystemCache(id)) { |
87 var packageDir = _getDirectory(id); | 87 var packageDir = getDirectory(id); |
88 ensureDir(path.dirname(packageDir)); | 88 ensureDir(path.dirname(packageDir)); |
89 var parsed = _parseDescription(id.description); | 89 var parsed = _parseDescription(id.description); |
90 await _download(parsed.last, parsed.first, id.version, packageDir); | 90 await _download(parsed.last, parsed.first, id.version, packageDir); |
91 } | 91 } |
92 | 92 |
93 return new Package.load(id.name, _getDirectory(id), systemCache.sources); | 93 return new Package.load(id.name, getDirectory(id), systemCache.sources); |
94 } | 94 } |
95 | 95 |
96 /// The system cache directory for the hosted source contains subdirectories | 96 /// The system cache directory for the hosted source contains subdirectories |
97 /// for each separate repository URL that's used on the system. | 97 /// for each separate repository URL that's used on the system. |
98 /// | 98 /// |
99 /// Each of these subdirectories then contains a subdirectory for each | 99 /// Each of these subdirectories then contains a subdirectory for each |
100 /// package downloaded from that site. | 100 /// package downloaded from that site. |
101 Future<String> getDirectory(PackageId id) => | 101 String getDirectory(PackageId id) { |
102 new Future.value(_getDirectory(id)); | |
103 | |
104 String _getDirectory(PackageId id) { | |
105 var parsed = _parseDescription(id.description); | 102 var parsed = _parseDescription(id.description); |
106 var dir = _urlToDirectory(parsed.last); | 103 var dir = _urlToDirectory(parsed.last); |
107 return path.join(systemCacheRoot, dir, "${parsed.first}-${id.version}"); | 104 return path.join(systemCacheRoot, dir, "${parsed.first}-${id.version}"); |
108 } | 105 } |
109 | 106 |
110 String packageName(description) => _parseDescription(description).first; | 107 String packageName(description) => _parseDescription(description).first; |
111 | 108 |
112 bool descriptionsEqual(description1, description2) => | 109 bool descriptionsEqual(description1, description2) => |
113 _parseDescription(description1) == _parseDescription(description2); | 110 _parseDescription(description1) == _parseDescription(description2); |
114 | 111 |
(...skipping 234 matching lines...) Loading... |
349 var name = description["name"]; | 346 var name = description["name"]; |
350 if (name is! String) { | 347 if (name is! String) { |
351 throw new FormatException("The 'name' key must have a string value."); | 348 throw new FormatException("The 'name' key must have a string value."); |
352 } | 349 } |
353 | 350 |
354 var url = description["url"]; | 351 var url = description["url"]; |
355 if (url == null) url = HostedSource.defaultUrl; | 352 if (url == null) url = HostedSource.defaultUrl; |
356 | 353 |
357 return new Pair<String, String>(name, url); | 354 return new Pair<String, String>(name, url); |
358 } | 355 } |
OLD | NEW |