Skip to content

Commit 0deff7b

Browse files
Merge branch 'user/ashdhin/v5-customization-CopyObject-IF-Match-E-Tag-If-Absent'
2 parents c74e864 + 0fc07c9 commit 0deff7b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

modules/AWSPowerShell/Cmdlets/S3/Advanced/Copy-S3Object-Cmdlet.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,28 @@ public class CopyS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
519519
public ChecksumMode ChecksumMode { get; set; }
520520
#endregion
521521

522+
#region Parameter IfMatch
523+
/// <summary>
524+
/// <para>Copies the object if the entity tag (ETag) of the destination object matches the specified tag. If the
525+
/// ETag values do not match, the operation returns a <code>412 Precondition Failed</code> error. If a concurrent
526+
/// operation occurs during the upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409
527+
/// failure you should fetch the object's ETag and retry the upload.</para>
528+
/// <para>Expects the ETag value as a string.</para>
529+
/// <para>For more information about conditional requests, see <a href=\"https://tools.ietf.org/html/rfc7232\">RFC 7232</a>.</para>
530+
/// </summary>
531+
[Parameter(ParameterSetName = CopyS3ObjectToS3Object, ValueFromPipelineByPropertyName = true)]
532+
public System.String IfMatch { get; set; }
533+
#endregion
534+
522535
#region Parameter IfNoneMatch
523536
/// <summary>
524-
/// <para>Uploads the object only if the object key name does not already exist in the bucket specified. Otherwise,
525-
/// Amazon S3 returns a <code>412 Precondition Failed</code> error.</para> <para>If a conflicting operation occurs
526-
/// during the upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409 failure you should
527-
/// re-initiate the multipart upload with <code>CreateMultipartUpload</code> and re-upload each part.</para> <para>Expects
528-
/// the '*' (asterisk) character.</para> <para>For more information about conditional requests,
529-
/// see <a href="https://tools.ietf.org/html/rfc7232">RFC 7232</a>, or <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-requests.html">Conditional requests</a>
530-
/// in the <i>Amazon S3 User Guide</i>.</para>
537+
/// <para>Copies the object only if the object key name at the destination does not already exist in the bucket specified.
538+
/// Otherwise, Amazon S3 returns a <code>412 Precondition Failed</code> error. If a concurrent operation occurs during the
539+
/// upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409 failure you should retry the upload.</para>
540+
/// <para>Expects the '*' (asterisk) character.</para> <para>For more information about conditional requests,
541+
/// see <a href=\"https://tools.ietf.org/html/rfc7232\">RFC 7232</a>.</para>
531542
/// </summary>
532-
[Parameter(ValueFromPipelineByPropertyName = true)]
543+
[Parameter(ParameterSetName = CopyS3ObjectToS3Object, ValueFromPipelineByPropertyName = true)]
533544
public System.String IfNoneMatch { get; set; }
534545
#endregion
535546

@@ -608,7 +619,6 @@ protected override void ProcessRecord()
608619
Metadata = this.Metadata,
609620
Headers = this.HeaderCollection,
610621

611-
IfNoneMatch = this.IfNoneMatch,
612622
RequestPayer = this.RequestPayer
613623
};
614624

@@ -684,6 +694,9 @@ protected override void ProcessRecord()
684694
context.ServerSideEncryptionMethod = AmazonS3Helper.Convert(this.ServerSideEncryption);
685695
}
686696

697+
if (!string.IsNullOrEmpty(this.IfMatch))
698+
context.IfMatch = this.IfMatch;
699+
687700
if (!string.IsNullOrEmpty(this.IfNoneMatch))
688701
context.IfNoneMatch = this.IfNoneMatch;
689702

@@ -855,6 +868,12 @@ private object CopyS3ObjectToS3(ExecutorContext context)
855868
if (cmdletContext.ExpectedBucketOwner != null)
856869
request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner;
857870

871+
if (!string.IsNullOrEmpty(cmdletContext.IfMatch))
872+
request.IfMatch = cmdletContext.IfMatch;
873+
874+
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
875+
request.IfNoneMatch = cmdletContext.IfNoneMatch;
876+
858877
AmazonS3Helper.SetMetadataAndHeaders(request, cmdletContext.Metadata, cmdletContext.Headers);
859878

860879
// issue call
@@ -945,6 +964,9 @@ private object MultipartCopyS3ObjectToS3(ExecutorContext context, long objectSiz
945964
PartETags = copyController.ETags
946965
};
947966

967+
if (!string.IsNullOrEmpty(cmdletContext.IfMatch))
968+
completeRequest.IfMatch = cmdletContext.IfMatch;
969+
948970
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
949971
completeRequest.IfNoneMatch = cmdletContext.IfNoneMatch;
950972

@@ -1276,6 +1298,7 @@ internal class CmdletContext : ExecutorContext
12761298
public ChecksumAlgorithm ChecksumAlgorithm { get; set; }
12771299
public ChecksumMode ChecksumMode { get; set; }
12781300

1301+
public String IfMatch { get; set; }
12791302
public String IfNoneMatch { get; set; }
12801303

12811304
public RequestPayer RequestPayer { get; set; }

0 commit comments

Comments
 (0)