| 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 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 var tempDir = systemCache.createTempDir(); | 75 var tempDir = systemCache.createTempDir(); |
| 76 return httpClient.send(new http.Request("GET", url)) | 76 return httpClient.send(new http.Request("GET", url)) |
| 77 .then((response) => response.stream) | 77 .then((response) => response.stream) |
| 78 .then((stream) { | 78 .then((stream) { |
| 79 return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT, | 79 return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT, |
| 80 'fetching URL "$url"'); | 80 'fetching URL "$url"'); |
| 81 }).then((_) { | 81 }).then((_) { |
| 82 // Now that the install has succeeded, move it to the real location in | 82 // Now that the install has succeeded, move it to the real location in |
| 83 // the cache. This ensures that we don't leave half-busted ghost | 83 // the cache. This ensures that we don't leave half-busted ghost |
| 84 // directories in the user's pub cache if an install fails. | 84 // directories in the user's pub cache if an install fails. |
| 85 return renameDir(tempDir, destPath); | 85 renameDir(tempDir, destPath); |
| 86 }).then((_) => true); | 86 return true; |
| 87 }); |
| 87 }); | 88 }); |
| 88 } | 89 } |
| 89 | 90 |
| 90 /// The system cache directory for the hosted source contains subdirectories | 91 /// The system cache directory for the hosted source contains subdirectories |
| 91 /// for each separate repository URL that's used on the system. Each of these | 92 /// for each separate repository URL that's used on the system. Each of these |
| 92 /// subdirectories then contains a subdirectory for each package installed | 93 /// subdirectories then contains a subdirectory for each package installed |
| 93 /// from that site. | 94 /// from that site. |
| 94 Future<String> systemCacheDirectory(PackageId id) { | 95 Future<String> systemCacheDirectory(PackageId id) { |
| 95 var parsed = _parseDescription(id.description); | 96 var parsed = _parseDescription(id.description); |
| 96 var url = _getSourceDirectory(parsed.last); | 97 var url = _getSourceDirectory(parsed.last); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 205 } |
| 205 | 206 |
| 206 var name = description["name"]; | 207 var name = description["name"]; |
| 207 if (name is! String) { | 208 if (name is! String) { |
| 208 throw new FormatException("The 'name' key must have a string value."); | 209 throw new FormatException("The 'name' key must have a string value."); |
| 209 } | 210 } |
| 210 | 211 |
| 211 var url = description.containsKey("url") ? description["url"] : _defaultUrl; | 212 var url = description.containsKey("url") ? description["url"] : _defaultUrl; |
| 212 return new Pair<String, String>(name, url); | 213 return new Pair<String, String>(name, url); |
| 213 } | 214 } |
| OLD | NEW |