Skip to content

Commit 2caa287

Browse files
Merge branch 'user/ashdhin/v4-customization-CopyObject-IF-Match-E-Tag-If-Absent' into v4.1
2 parents 4d19634 + 5e2b5a2 commit 2caa287

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
@@ -540,17 +540,28 @@ public class CopyS3ObjectCmdlet : AmazonS3ClientCmdlet, IExecutor
540540
public ChecksumMode ChecksumMode { get; set; }
541541
#endregion
542542

543+
#region Parameter IfMatch
544+
/// <summary>
545+
/// <para>Copies the object if the entity tag (ETag) of the destination object matches the specified tag. If the
546+
/// ETag values do not match, the operation returns a <code>412 Precondition Failed</code> error. If a concurrent
547+
/// operation occurs during the upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409
548+
/// failure you should fetch the object's ETag and retry the upload.</para>
549+
/// <para>Expects the ETag value as a string.</para>
550+
/// <para>For more information about conditional requests, see <a href=\"https://tools.ietf.org/html/rfc7232\">RFC 7232</a>.</para>
551+
/// </summary>
552+
[Parameter(ParameterSetName = CopyS3ObjectToS3Object, ValueFromPipelineByPropertyName = true)]
553+
public System.String IfMatch { get; set; }
554+
#endregion
555+
543556
#region Parameter IfNoneMatch
544557
/// <summary>
545-
/// <para>Uploads the object only if the object key name does not already exist in the bucket specified. Otherwise,
546-
/// Amazon S3 returns a <code>412 Precondition Failed</code> error.</para> <para>If a conflicting operation occurs
547-
/// during the upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409 failure you should
548-
/// re-initiate the multipart upload with <code>CreateMultipartUpload</code> and re-upload each part.</para> <para>Expects
549-
/// the '*' (asterisk) character.</para> <para>For more information about conditional requests,
550-
/// 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>
551-
/// in the <i>Amazon S3 User Guide</i>.</para>
558+
/// <para>Copies the object only if the object key name at the destination does not already exist in the bucket specified.
559+
/// Otherwise, Amazon S3 returns a <code>412 Precondition Failed</code> error. If a concurrent operation occurs during the
560+
/// upload S3 returns a <code>409 ConditionalRequestConflict</code> response. On a 409 failure you should retry the upload.</para>
561+
/// <para>Expects the '*' (asterisk) character.</para> <para>For more information about conditional requests,
562+
/// see <a href=\"https://tools.ietf.org/html/rfc7232\">RFC 7232</a>.</para>
552563
/// </summary>
553-
[Parameter(ValueFromPipelineByPropertyName = true)]
564+
[Parameter(ParameterSetName = CopyS3ObjectToS3Object, ValueFromPipelineByPropertyName = true)]
554565
public System.String IfNoneMatch { get; set; }
555566
#endregion
556567

@@ -612,7 +623,6 @@ protected override void ProcessRecord()
612623
Metadata = this.Metadata,
613624
Headers = this.HeaderCollection,
614625

615-
IfNoneMatch = this.IfNoneMatch,
616626
RequestPayer = this.RequestPayer
617627
};
618628

@@ -692,6 +702,9 @@ protected override void ProcessRecord()
692702
context.ServerSideEncryptionMethod = AmazonS3Helper.Convert(this.ServerSideEncryption);
693703
}
694704

705+
if (!string.IsNullOrEmpty(this.IfMatch))
706+
context.IfMatch = this.IfMatch;
707+
695708
if (!string.IsNullOrEmpty(this.IfNoneMatch))
696709
context.IfNoneMatch = this.IfNoneMatch;
697710

@@ -869,6 +882,12 @@ private object CopyS3ObjectToS3(ExecutorContext context)
869882
if (cmdletContext.ExpectedBucketOwner != null)
870883
request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner;
871884

885+
if (!string.IsNullOrEmpty(cmdletContext.IfMatch))
886+
request.IfMatch = cmdletContext.IfMatch;
887+
888+
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
889+
request.IfNoneMatch = cmdletContext.IfNoneMatch;
890+
872891
AmazonS3Helper.SetMetadataAndHeaders(request, cmdletContext.Metadata, cmdletContext.Headers);
873892

874893
// issue call
@@ -959,6 +978,9 @@ private object MultipartCopyS3ObjectToS3(ExecutorContext context, long objectSiz
959978
PartETags = copyController.ETags
960979
};
961980

981+
if (!string.IsNullOrEmpty(cmdletContext.IfMatch))
982+
completeRequest.IfMatch = cmdletContext.IfMatch;
983+
962984
if (!string.IsNullOrEmpty(cmdletContext.IfNoneMatch))
963985
completeRequest.IfNoneMatch = cmdletContext.IfNoneMatch;
964986

@@ -1360,6 +1382,7 @@ internal class CmdletContext : ExecutorContext
13601382
public ChecksumAlgorithm ChecksumAlgorithm { get; set; }
13611383
public ChecksumMode ChecksumMode { get; set; }
13621384

1385+
public String IfMatch { get; set; }
13631386
public String IfNoneMatch { get; set; }
13641387

13651388
public RequestPayer RequestPayer { get; set; }

0 commit comments

Comments
 (0)