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

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

Issue 13332009: Make listDir and createSymlink synchronous in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
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 hosted_source; 5 library hosted_source;
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:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 /// 111 ///
112 /// There are two valid formats. A plain string refers to a package with the 112 /// There are two valid formats. A plain string refers to a package with the
113 /// given name from the default host, while a map with keys "name" and "url" 113 /// given name from the default host, while a map with keys "name" and "url"
114 /// refers to a package with the given name from the host at the given URL. 114 /// refers to a package with the given name from the host at the given URL.
115 dynamic parseDescription(String containingPath, description, 115 dynamic parseDescription(String containingPath, description,
116 {bool fromLockFile: false}) { 116 {bool fromLockFile: false}) {
117 _parseDescription(description); 117 _parseDescription(description);
118 return description; 118 return description;
119 } 119 }
120 120
121 Future<List<Package>> getCachedPackages() { 121 Future<List<Package>> getCachedPackages() {
Bob Nystrom 2013/03/29 21:22:06 Make this sync too.
nweiz 2013/03/29 22:09:02 Done, although we may have to move it back to asyn
122 return defer(() { 122 return defer(() {
123 var cacheDir = path.join(systemCacheRoot, 123 var cacheDir = path.join(systemCacheRoot,
124 _getSourceDirectory(_defaultUrl)); 124 _getSourceDirectory(_defaultUrl));
125 if (!dirExists(cacheDir)) return []; 125 if (!dirExists(cacheDir)) return [];
126 126
127 return listDir(path.join(cacheDir)).then((entries) { 127 return listDir(path.join(cacheDir)).map((entry) =>
128 return entries.map((entry) =>
129 new Package.load(null, entry, systemCache.sources)); 128 new Package.load(null, entry, systemCache.sources));
130 });
131 }); 129 });
132 } 130 }
133 131
134 /// When an error occurs trying to read something about [package] from [url], 132 /// When an error occurs trying to read something about [package] from [url],
135 /// this tries to translate into a more user friendly error message. Always 133 /// this tries to translate into a more user friendly error message. Always
136 /// throws an error, either the original one or a better one. 134 /// throws an error, either the original one or a better one.
137 void _throwFriendlyError(AsyncError asyncError, package, url) { 135 void _throwFriendlyError(AsyncError asyncError, package, url) {
138 if (asyncError.error is PubHttpException && 136 if (asyncError.error is PubHttpException &&
139 asyncError.error.response.statusCode == 404) { 137 asyncError.error.response.statusCode == 404) {
140 throw 'Could not find package "$package" at $url.'; 138 throw 'Could not find package "$package" at $url.';
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 202 }
205 203
206 var name = description["name"]; 204 var name = description["name"];
207 if (name is! String) { 205 if (name is! String) {
208 throw new FormatException("The 'name' key must have a string value."); 206 throw new FormatException("The 'name' key must have a string value.");
209 } 207 }
210 208
211 var url = description.containsKey("url") ? description["url"] : _defaultUrl; 209 var url = description.containsKey("url") ? description["url"] : _defaultUrl;
212 return new Pair<String, String>(name, url); 210 return new Pair<String, String>(name, url);
213 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698