| 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:io', prefix: 'io'); |
| 7 #import('dart:json'); | 8 #import('dart:json'); |
| 8 #import('dart:uri'); | 9 #import('dart:uri'); |
| 10 |
| 9 #import('io.dart'); | 11 #import('io.dart'); |
| 10 #import('package.dart'); | 12 #import('package.dart'); |
| 11 #import('pubspec.dart'); | 13 #import('pubspec.dart'); |
| 12 #import('source.dart'); | 14 #import('source.dart'); |
| 13 #import('source_registry.dart'); | 15 #import('source_registry.dart'); |
| 14 #import('utils.dart'); | 16 #import('utils.dart'); |
| 15 #import('version.dart'); | 17 #import('version.dart'); |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * A package source that installs packages from a package hosting site that | 20 * A package source that installs packages from a package hosting site that |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 65 |
| 64 /** | 66 /** |
| 65 * Downloads a package from the site and unpacks it. | 67 * Downloads a package from the site and unpacks it. |
| 66 */ | 68 */ |
| 67 Future<bool> install(PackageId id, String destPath) { | 69 Future<bool> install(PackageId id, String destPath) { |
| 68 var parsedDescription = _parseDescription(id.description); | 70 var parsedDescription = _parseDescription(id.description); |
| 69 var name = parsedDescription.first; | 71 var name = parsedDescription.first; |
| 70 var url = parsedDescription.last; | 72 var url = parsedDescription.last; |
| 71 | 73 |
| 72 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; | 74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; |
| 75 |
| 73 return Futures.wait([httpGet(fullUrl), ensureDir(destPath)]).chain((args) { | 76 return Futures.wait([httpGet(fullUrl), ensureDir(destPath)]).chain((args) { |
| 74 return timeout(extractTarGz(args[0], args[1]), HTTP_TIMEOUT, | 77 return timeout(extractTarGz(args[0], args[1]), HTTP_TIMEOUT, |
| 75 'Timed out while fetching URL "$fullUrl".'); | 78 'Timed out while fetching URL "$fullUrl".'); |
| 79 }).transformException((ex) { |
| 80 // If the install failed, delete the directory. Prevents leaving a ghost |
| 81 // directory in the system cache which would later make pub think the |
| 82 // install succeeded. |
| 83 // TODO(rnystrom): Use deleteDir() here when transformException() supports |
| 84 // returning a future. Also remove dart:io import then. |
| 85 new io.Directory(destPath).deleteRecursivelySync(); |
| 86 |
| 87 throw ex; |
| 76 }); | 88 }); |
| 77 } | 89 } |
| 78 | 90 |
| 79 /** | 91 /** |
| 80 * The system cache directory for the hosted source contains subdirectories | 92 * The system cache directory for the hosted source contains subdirectories |
| 81 * for each separate repository URL that's used on the system. Each of these | 93 * for each separate repository URL that's used on the system. Each of these |
| 82 * subdirectories then contains a subdirectory for each package installed | 94 * subdirectories then contains a subdirectory for each package installed |
| 83 * from that site. | 95 * from that site. |
| 84 */ | 96 */ |
| 85 String systemCacheDirectory(PackageId id) { | 97 String systemCacheDirectory(PackageId id) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 142 |
| 131 var name = description["name"]; | 143 var name = description["name"]; |
| 132 if (name is! String) { | 144 if (name is! String) { |
| 133 throw new FormatException("The 'name' key must have a string value."); | 145 throw new FormatException("The 'name' key must have a string value."); |
| 134 } | 146 } |
| 135 | 147 |
| 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 148 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
| 137 return new Pair<String, String>(name, url); | 149 return new Pair<String, String>(name, url); |
| 138 } | 150 } |
| 139 } | 151 } |
| OLD | NEW |