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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 /// given name from the default host, while a map with keys "name" and "url" | 118 /// given name from the default host, while a map with keys "name" and "url" |
119 /// refers to a package with the given name from the host at the given URL. | 119 /// refers to a package with the given name from the host at the given URL. |
120 dynamic parseDescription(String containingPath, description, | 120 dynamic parseDescription(String containingPath, description, |
121 {bool fromLockFile: false}) { | 121 {bool fromLockFile: false}) { |
122 _parseDescription(description); | 122 _parseDescription(description); |
123 return description; | 123 return description; |
124 } | 124 } |
125 | 125 |
126 /// Re-downloads all packages that have been previously downloaded into the | 126 /// Re-downloads all packages that have been previously downloaded into the |
127 /// system cache from any server. | 127 /// system cache from any server. |
128 Future<Pair<int, int>> repairCachedPackages() async { | 128 Future<Pair<List<PackageId>, List<PackageId>>> repairCachedPackages() async { |
129 if (!dirExists(systemCacheRoot)) return new Pair(0, 0); | 129 if (!dirExists(systemCacheRoot)) return new Pair([], []); |
130 | 130 |
131 var successes = 0; | 131 var successes = []; |
132 var failures = 0; | 132 var failures = []; |
133 | 133 |
134 for (var serverDir in listDir(systemCacheRoot)) { | 134 for (var serverDir in listDir(systemCacheRoot)) { |
135 var url = _directoryToUrl(path.basename(serverDir)); | 135 var url = _directoryToUrl(path.basename(serverDir)); |
136 var packages = _getCachedPackagesInDirectory(path.basename(serverDir)); | 136 var packages = _getCachedPackagesInDirectory(path.basename(serverDir)); |
137 packages.sort(Package.orderByNameAndVersion); | 137 packages.sort(Package.orderByNameAndVersion); |
138 | 138 |
139 for (var package in packages) { | 139 for (var package in packages) { |
| 140 var id = new PackageId(package.name, this.name, package.version, null); |
| 141 |
140 try { | 142 try { |
141 await _download(url, package.name, package.version, package.dir); | 143 await _download(url, package.name, package.version, package.dir); |
142 successes++; | 144 successes.add(id); |
143 } catch (error, stackTrace) { | 145 } catch (error, stackTrace) { |
144 failures++; | 146 failures.add(id); |
145 var message = "Failed to repair ${log.bold(package.name)} " | 147 var message = "Failed to repair ${log.bold(package.name)} " |
146 "${package.version}"; | 148 "${package.version}"; |
147 if (url != defaultUrl) message += " from $url"; | 149 if (url != defaultUrl) message += " from $url"; |
148 log.error("$message. Error:\n$error"); | 150 log.error("$message. Error:\n$error"); |
149 log.fine(stackTrace); | 151 log.fine(stackTrace); |
150 | 152 |
151 tryDeleteEntry(package.dir); | 153 tryDeleteEntry(package.dir); |
152 } | 154 } |
153 } | 155 } |
154 } | 156 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 var name = description["name"]; | 349 var name = description["name"]; |
348 if (name is! String) { | 350 if (name is! String) { |
349 throw new FormatException("The 'name' key must have a string value."); | 351 throw new FormatException("The 'name' key must have a string value."); |
350 } | 352 } |
351 | 353 |
352 var url = description["url"]; | 354 var url = description["url"]; |
353 if (url == null) url = HostedSource.defaultUrl; | 355 if (url == null) url = HostedSource.defaultUrl; |
354 | 356 |
355 return new Pair<String, String>(name, url); | 357 return new Pair<String, String>(name, url); |
356 } | 358 } |
OLD | NEW |