OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 pub_dartlang_org.backend; | 5 library pub_dartlang_org.backend; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:gcloud/db.dart'; | 10 import 'package:gcloud/db.dart'; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 307 |
308 // Try to load all package versions, sort them by `sort_order` and | 308 // Try to load all package versions, sort them by `sort_order` and |
309 // store them again. | 309 // store them again. |
310 await _updatePackageSortIndex(package.key); | 310 await _updatePackageSortIndex(package.key); |
311 | 311 |
312 return new PackageVersion( | 312 return new PackageVersion( |
313 newVersion.package, newVersion.version, | 313 newVersion.package, newVersion.version, |
314 newVersion.pubspec.jsonString); | 314 newVersion.pubspec.jsonString); |
315 } catch (error, stack) { | 315 } catch (error, stack) { |
316 _logger.warning('Error while committing: $error, $stack'); | 316 _logger.warning('Error while committing: $error, $stack'); |
317 await T.rollback(); | 317 |
| 318 // This call might fail if the transaction has already been |
| 319 // committed/rolled back or the transaction failed. |
| 320 // |
| 321 // In which case we simply ignore the rollback error and rethrow the |
| 322 // original error. |
| 323 try { |
| 324 await T.rollback(); |
| 325 } catch (_) {} |
318 rethrow; | 326 rethrow; |
319 } | 327 } |
320 }); | 328 }); |
321 } | 329 } |
322 | 330 |
323 Future _updatePackageSortIndex(Key packageKey) async { | 331 Future _updatePackageSortIndex(Key packageKey) async { |
324 try { | 332 try { |
325 _logger.info('Trying to update the `sort_order` field.'); | 333 _logger.info('Trying to update the `sort_order` field.'); |
326 await db.withTransaction((Transaction T) async { | 334 await db.withTransaction((Transaction T) async { |
327 List<models.PackageVersion> versions = await | 335 List<models.PackageVersion> versions = await |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 | 744 |
737 /// The GCS object name of an temporary object [guid] - excluding leading '/'. | 745 /// The GCS object name of an temporary object [guid] - excluding leading '/'. |
738 String tmpObjectName(String guid) => 'tmp/$guid'; | 746 String tmpObjectName(String guid) => 'tmp/$guid'; |
739 | 747 |
740 /// The http URL of a publicly accessable GCS object. | 748 /// The http URL of a publicly accessable GCS object. |
741 String tarballObjectUrl(String package, String version) { | 749 String tarballObjectUrl(String package, String version) { |
742 var object = tarballObjectName(package, version); | 750 var object = tarballObjectName(package, version); |
743 return 'https://storage.googleapis.com/${bucket}/${object}'; | 751 return 'https://storage.googleapis.com/${bucket}/${object}'; |
744 } | 752 } |
745 } | 753 } |
OLD | NEW |