@@ -854,6 +854,28 @@ class File extends ServiceObject<File> { |
854 | 854 | this.instancePreconditionOpts = options?.preconditionOpts; |
855 | 855 | } |
856 | 856 |
|
| 857 | + /** |
| 858 | + * A helper method for determining if a request should be retried based on preconditions. |
| 859 | + * This should only be used for methods where the idempotency is determined by |
| 860 | + * `ifGenerationMatch` |
| 861 | + * |
| 862 | + * A request should not be retried under the following conditions: |
| 863 | + * - if precondition option `ifGenerationMatch` is not set OR |
| 864 | + * - if `idempotencyStrategy` is set to `RetryNever` |
| 865 | + */ |
| 866 | + private shouldRetryBasedOnPreconditionAndIdempotencyStrat( |
| 867 | + options?: PreconditionOptions |
| 868 | + ): boolean { |
| 869 | + return !( |
| 870 | + (options?.ifGenerationMatch === undefined && |
| 871 | + this.instancePreconditionOpts?.ifGenerationMatch === undefined && |
| 872 | + this.storage.retryOptions.idempotencyStrategy === |
| 873 | + IdempotencyStrategy.RetryConditional) || |
| 874 | + this.storage.retryOptions.idempotencyStrategy === |
| 875 | + IdempotencyStrategy.RetryNever |
| 876 | + ); |
| 877 | + } |
| 878 | + |
857 | 879 | copy( |
858 | 880 | destination: string | Bucket | File, |
859 | 881 | options?: CopyOptions |
@@ -3667,15 +3689,11 @@ class File extends ServiceObject<File> { |
3667 | 3689 | const options = |
3668 | 3690 | typeof optionsOrCallback === 'object' ? optionsOrCallback : {}; |
3669 | 3691 |
|
3670 | | - // Do not retry if precondition option ifGenerationMatch is not set |
3671 | 3692 | let maxRetries = this.storage.retryOptions.maxRetries; |
3672 | 3693 | if ( |
3673 | | - (options?.preconditionOpts?.ifGenerationMatch === undefined && |
3674 | | - this.instancePreconditionOpts?.ifGenerationMatch === undefined && |
3675 | | - this.storage.retryOptions.idempotencyStrategy === |
3676 | | - IdempotencyStrategy.RetryConditional) || |
3677 | | - this.storage.retryOptions.idempotencyStrategy === |
3678 | | - IdempotencyStrategy.RetryNever |
| 3694 | + !this.shouldRetryBasedOnPreconditionAndIdempotencyStrat( |
| 3695 | + options?.preconditionOpts |
| 3696 | + ) |
3679 | 3697 | ) { |
3680 | 3698 | maxRetries = 0; |
3681 | 3699 | } |
@@ -3852,15 +3870,11 @@ class File extends ServiceObject<File> { |
3852 | 3870 | options |
3853 | 3871 | ); |
3854 | 3872 |
|
3855 | | - // Do not retry if precondition option ifGenerationMatch is not set |
3856 | 3873 | const retryOptions = this.storage.retryOptions; |
3857 | 3874 | if ( |
3858 | | - (options?.preconditionOpts?.ifGenerationMatch === undefined && |
3859 | | - this.instancePreconditionOpts?.ifGenerationMatch === undefined && |
3860 | | - this.storage.retryOptions.idempotencyStrategy === |
3861 | | - IdempotencyStrategy.RetryConditional) || |
3862 | | - this.storage.retryOptions.idempotencyStrategy === |
3863 | | - IdempotencyStrategy.RetryNever |
| 3875 | + !this.shouldRetryBasedOnPreconditionAndIdempotencyStrat( |
| 3876 | + options?.preconditionOpts |
| 3877 | + ) |
3864 | 3878 | ) { |
3865 | 3879 | retryOptions.autoRetry = false; |
3866 | 3880 | } |
|