| 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 command_lish; | 5 library command_lish; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:json'; | 9 import 'dart:json'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 request.followRedirects = false; | 76 request.followRedirects = false; |
| 77 request.files.add(new http.MultipartFile.fromBytes( | 77 request.files.add(new http.MultipartFile.fromBytes( |
| 78 'file', packageBytes, filename: 'package.tar.gz')); | 78 'file', packageBytes, filename: 'package.tar.gz')); |
| 79 return client.send(request); | 79 return client.send(request); |
| 80 }).then(http.Response.fromStream).then((response) { | 80 }).then(http.Response.fromStream).then((response) { |
| 81 var location = response.headers['location']; | 81 var location = response.headers['location']; |
| 82 if (location == null) throw new PubHttpException(response); | 82 if (location == null) throw new PubHttpException(response); |
| 83 return location; | 83 return location; |
| 84 }).then((location) => client.get(location)) | 84 }).then((location) => client.get(location)) |
| 85 .then(handleJsonSuccess); | 85 .then(handleJsonSuccess); |
| 86 }).catchError((asyncError) { | 86 }).catchError((error) { |
| 87 if (asyncError.error is! PubHttpException) throw asyncError; | 87 if (error is! PubHttpException) throw error; |
| 88 var url = asyncError.error.response.request.url; | 88 var url = error.response.request.url; |
| 89 if (urisEqual(url, cloudStorageUrl)) { | 89 if (urisEqual(url, cloudStorageUrl)) { |
| 90 // TODO(nweiz): the response may have XML-formatted information about | 90 // TODO(nweiz): the response may have XML-formatted information about |
| 91 // the error. Try to parse that out once we have an easily-accessible | 91 // the error. Try to parse that out once we have an easily-accessible |
| 92 // XML parser. | 92 // XML parser. |
| 93 throw 'Failed to upload the package.'; | 93 throw 'Failed to upload the package.'; |
| 94 } else if (urisEqual(Uri.parse(url.origin), Uri.parse(server.origin))) { | 94 } else if (urisEqual(Uri.parse(url.origin), Uri.parse(server.origin))) { |
| 95 handleJsonError(asyncError.error.response); | 95 handleJsonError(error.response); |
| 96 } else { | 96 } else { |
| 97 throw asyncError; | 97 throw error; |
| 98 } | 98 } |
| 99 }); | 99 }); |
| 100 } | 100 } |
| 101 | 101 |
| 102 Future onRun() { | 102 Future onRun() { |
| 103 if (force && dryRun) { | 103 if (force && dryRun) { |
| 104 log.error('Cannot use both --force and --dry-run.'); | 104 log.error('Cannot use both --force and --dry-run.'); |
| 105 this.printUsage(); | 105 this.printUsage(); |
| 106 exit(exit_codes.USAGE); | 106 exit(exit_codes.USAGE); |
| 107 } | 107 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return confirm(message).then((confirmed) { | 198 return confirm(message).then((confirmed) { |
| 199 if (!confirmed) { | 199 if (!confirmed) { |
| 200 log.error("Package upload canceled."); | 200 log.error("Package upload canceled."); |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 return true; | 203 return true; |
| 204 }); | 204 }); |
| 205 }); | 205 }); |
| 206 } | 206 } |
| 207 } | 207 } |
| OLD | NEW |