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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart

Issue 887223007: Revert "Use native async/await support in pub." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart
diff --git a/sdk/lib/_internal/pub/lib/src/source/hosted.dart b/sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart
similarity index 66%
copy from sdk/lib/_internal/pub/lib/src/source/hosted.dart
copy to sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart
index f1649d1c17d7a56d08e652c5aa014bf606d73f80..37f27990ee55af76321848678e218e2a53c6f7ad 100644
--- a/sdk/lib/_internal/pub/lib/src/source/hosted.dart
+++ b/sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart
@@ -38,15 +38,14 @@ class HostedSource extends CachedSource {
/// Downloads a list of all versions of a package that are available from the
/// site.
Future<List<Version>> getVersions(String name, description) {
- var url = _makeUrl(description,
- (server, package) => "$server/api/packages/$package");
+ var url =
+ _makeUrl(description, (server, package) => "$server/api/packages/$package");
log.io("Get versions from $url.");
return httpClient.read(url, headers: PUB_API_HEADERS).then((body) {
var doc = JSON.decode(body);
- return doc['versions']
- .map((version) => new Version.parse(version['version']))
- .toList();
+ return doc['versions'].map(
+ (version) => new Version.parse(version['version'])).toList();
}).catchError((ex, stackTrace) {
var parsed = _parseDescription(description);
_throwFriendlyError(ex, stackTrace, parsed.first, parsed.last);
@@ -57,8 +56,10 @@ class HostedSource extends CachedSource {
/// is available from the site.
Future<Pubspec> describeUncached(PackageId id) {
// Request it from the server.
- var url = _makeVersionUrl(id, (server, package, version) =>
- "$server/api/packages/$package/versions/$version");
+ var url = _makeVersionUrl(
+ id,
+ (server, package, version) =>
+ "$server/api/packages/$package/versions/$version");
log.io("Describe package at $url.");
return httpClient.read(url, headers: PUB_API_HEADERS).then((version) {
@@ -68,8 +69,11 @@ class HostedSource extends CachedSource {
// a secondary cache of just pubspecs. This would let us have a
// persistent cache for pubspecs for packages that haven't actually
// been downloaded.
- return new Pubspec.fromMap(version['pubspec'], systemCache.sources,
- expectedName: id.name, location: url);
+ return new Pubspec.fromMap(
+ version['pubspec'],
+ systemCache.sources,
+ expectedName: id.name,
+ location: url);
}).catchError((ex, stackTrace) {
var parsed = _parseDescription(id.description);
_throwFriendlyError(ex, stackTrace, id.name, parsed.last);
@@ -117,42 +121,109 @@ class HostedSource extends CachedSource {
/// given name from the default host, while a map with keys "name" and "url"
/// refers to a package with the given name from the host at the given URL.
dynamic parseDescription(String containingPath, description,
- {bool fromLockFile: false}) {
+ {bool fromLockFile: false}) {
_parseDescription(description);
return description;
}
/// Re-downloads all packages that have been previously downloaded into the
/// system cache from any server.
- Future<Pair<int, int>> repairCachedPackages() async {
- if (!dirExists(systemCacheRoot)) return new Pair(0, 0);
-
- var successes = 0;
- var failures = 0;
-
- for (var serverDir in listDir(systemCacheRoot)) {
- var url = _directoryToUrl(path.basename(serverDir));
- var packages = _getCachedPackagesInDirectory(path.basename(serverDir));
- packages.sort(Package.orderByNameAndVersion);
-
- for (var package in packages) {
- try {
- await _download(url, package.name, package.version, package.dir);
- successes++;
- } catch (error, stackTrace) {
- failures++;
- var message = "Failed to repair ${log.bold(package.name)} "
- "${package.version}";
- if (url != defaultUrl) message += " from $url";
- log.error("$message. Error:\n$error");
- log.fine(stackTrace);
-
- tryDeleteEntry(package.dir);
+ Future<Pair<int, int>> repairCachedPackages() {
+ final completer0 = new Completer();
+ scheduleMicrotask(() {
+ try {
+ join0() {
+ var successes = 0;
+ var failures = 0;
+ var it0 = listDir(systemCacheRoot).iterator;
+ break0() {
+ completer0.complete(new Pair(successes, failures));
+ }
+ var trampoline0;
+ continue0() {
+ trampoline0 = null;
+ if (it0.moveNext()) {
+ var serverDir = it0.current;
+ var url = _directoryToUrl(path.basename(serverDir));
+ var packages =
+ _getCachedPackagesInDirectory(path.basename(serverDir));
+ packages.sort(Package.orderByNameAndVersion);
+ var it1 = packages.iterator;
+ break1() {
+ trampoline0 = continue0;
+ do trampoline0(); while (trampoline0 != null);
+ }
+ var trampoline1;
+ continue1() {
+ trampoline1 = null;
+ if (it1.moveNext()) {
+ var package = it1.current;
+ join1() {
+ trampoline1 = continue1;
+ do trampoline1(); while (trampoline1 != null);
+ }
+ catch0(error, stackTrace) {
+ try {
+ failures++;
+ var message =
+ "Failed to repair ${log.bold(package.name)} " "${package.version}";
+ join2() {
+ log.error("${message}. Error:\n${error}");
+ log.fine(stackTrace);
+ tryDeleteEntry(package.dir);
+ join1();
+ }
+ if (url != defaultUrl) {
+ message += " from ${url}";
+ join2();
+ } else {
+ join2();
+ }
+ } catch (error, stackTrace) {
+ completer0.completeError(error, stackTrace);
+ }
+ }
+ try {
+ new Future.value(
+ _download(url, package.name, package.version, package.dir)).then((x0) {
+ trampoline1 = () {
+ trampoline1 = null;
+ try {
+ x0;
+ successes++;
+ join1();
+ } catch (e0, s0) {
+ catch0(e0, s0);
+ }
+ };
+ do trampoline1(); while (trampoline1 != null);
+ }, onError: catch0);
+ } catch (e1, s1) {
+ catch0(e1, s1);
+ }
+ } else {
+ break1();
+ }
+ }
+ trampoline1 = continue1;
+ do trampoline1(); while (trampoline1 != null);
+ } else {
+ break0();
+ }
+ }
+ trampoline0 = continue0;
+ do trampoline0(); while (trampoline0 != null);
}
+ if (!dirExists(systemCacheRoot)) {
+ completer0.complete(new Pair(0, 0));
+ } else {
+ join0();
+ }
+ } catch (e, s) {
+ completer0.completeError(e, s);
}
- }
-
- return new Pair(successes, failures);
+ });
+ return completer0.future;
}
/// Gets all of the packages that have been downloaded into the system cache
@@ -167,9 +238,9 @@ class HostedSource extends CachedSource {
var cacheDir = path.join(systemCacheRoot, dir);
if (!dirExists(cacheDir)) return [];
- return listDir(cacheDir)
- .map((entry) => new Package.load(null, entry, systemCache.sources))
- .toList();
+ return listDir(
+ cacheDir).map(
+ (entry) => new Package.load(null, entry, systemCache.sources)).toList();
}
/// Downloads package [package] at [version] from [server], and unpacks it
@@ -183,10 +254,14 @@ class HostedSource extends CachedSource {
// Download and extract the archive to a temp directory.
var tempDir = systemCache.createTempDir();
- return httpClient.send(new http.Request("GET", url))
- .then((response) => response.stream)
- .then((stream) {
- return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT, url,
+ return httpClient.send(
+ new http.Request(
+ "GET",
+ url)).then((response) => response.stream).then((stream) {
+ return timeout(
+ extractTarGz(stream, tempDir),
+ HTTP_TIMEOUT,
+ url,
'downloading $url');
}).then((_) {
// Remove the existing directory if it exists. This will happen if
@@ -208,20 +283,25 @@ class HostedSource extends CachedSource {
/// Always throws an error, either the original one or a better one.
void _throwFriendlyError(error, StackTrace stackTrace, String package,
String url) {
- if (error is PubHttpException &&
- error.response.statusCode == 404) {
+ if (error is PubHttpException && error.response.statusCode == 404) {
throw new PackageNotFoundException(
- "Could not find package $package at $url.", error, stackTrace);
+ "Could not find package $package at $url.",
+ error,
+ stackTrace);
}
if (error is TimeoutException) {
- fail("Timed out trying to find package $package at $url.",
- error, stackTrace);
+ fail(
+ "Timed out trying to find package $package at $url.",
+ error,
+ stackTrace);
}
if (error is io.SocketException) {
- fail("Got socket error trying to find package $package at $url.",
- error, stackTrace);
+ fail(
+ "Got socket error trying to find package $package at $url.",
+ error,
+ stackTrace);
}
// Otherwise re-throw the original exception.
@@ -240,12 +320,12 @@ class OfflineHostedSource extends HostedSource {
return newFuture(() {
var parsed = _parseDescription(description);
var server = parsed.last;
- log.io("Finding versions of $name in "
- "$systemCacheRoot/${_urlToDirectory(server)}");
- return _getCachedPackagesInDirectory(_urlToDirectory(server))
- .where((package) => package.name == name)
- .map((package) => package.version)
- .toList();
+ log.io(
+ "Finding versions of $name in " "$systemCacheRoot/${_urlToDirectory(server)}");
+ return _getCachedPackagesInDirectory(
+ _urlToDirectory(
+ server)).where(
+ (package) => package.name == name).map((package) => package.version).toList();
}).then((versions) {
// If there are no versions in the cache, report a clearer error.
if (versions.isEmpty) fail("Could not find package $name in cache.");
@@ -285,9 +365,12 @@ class OfflineHostedSource extends HostedSource {
/// This behavior is a bug, but is being preserved for compatibility.
String _urlToDirectory(String url) {
// Normalize all loopback URLs to "localhost".
- url = url.replaceAllMapped(new RegExp(r"^https?://(127\.0\.0\.1|\[::1\])?"),
+ url = url.replaceAllMapped(
+ new RegExp(r"^https?://(127\.0\.0\.1|\[::1\])?"),
(match) => match[1] == null ? '' : 'localhost');
- return replace(url, new RegExp(r'[<>:"\\/|?*%]'),
+ return replace(
+ url,
+ new RegExp(r'[<>:"\\/|?*%]'),
(match) => '%${match[0].codeUnitAt(0)}');
}
@@ -329,8 +412,8 @@ Uri _makeUrl(description, String pattern(String server, String package)) {
/// converts that to a Uri given [pattern].
///
/// Ensures the package name is properly URL encoded.
-Uri _makeVersionUrl(PackageId id,
- String pattern(String server, String package, String version)) {
+Uri _makeVersionUrl(PackageId id, String pattern(String server, String package,
+ String version)) {
var parsed = _parseDescription(id.description);
var server = parsed.last;
var package = Uri.encodeComponent(parsed.first);
@@ -348,13 +431,11 @@ Pair<String, String> _parseDescription(description) {
}
if (description is! Map) {
- throw new FormatException(
- "The description must be a package name or map.");
+ throw new FormatException("The description must be a package name or map.");
}
if (!description.containsKey("name")) {
- throw new FormatException(
- "The description map must contain a 'name' key.");
+ throw new FormatException("The description map must contain a 'name' key.");
}
var name = description["name"];
« no previous file with comments | « sdk/lib/_internal/pub_generated/lib/src/source/git.dart ('k') | sdk/lib/_internal/pub_generated/lib/src/source/path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698