Skip to content

Adding No overwrite for copy operation#9592

Merged
aemous merged 2 commits into
aws:s3-no-overwritefrom
rakshil14-2:no_overwrite_feature_for_copy_operation
Jul 25, 2025
Merged

Adding No overwrite for copy operation#9592
aemous merged 2 commits into
aws:s3-no-overwritefrom
rakshil14-2:no_overwrite_feature_for_copy_operation

Conversation

@rakshil14-2
Copy link
Copy Markdown

@rakshil14-2 rakshil14-2 commented Jul 14, 2025

Issue : Github Issue #2874

Description of changes:

Customers requested to prevent overwriting of objects. This is done by providing no-overwrite header using ifNoneMatch with Etags to transfer objects that are not present on the bucket. However, retrieval of etags is difficult hence during copy operation always perform multipart copy since it follows multipart upload approach which indeed supports ifNoneMatch header without Etags. The no-overwrite header works well with other cp command headers. Customer can be implemented using aws s3 cp <source> <destination> --no-overwrite which allows successful transfers when object with the same name is not present on the destination. However, if the user tries to transfer the object which is already present at the target bucket using command line, a warning about skipping the file will be generated and that object is not allowed to transfer to S3 bucket.

Testing:
Functional testing is performed to validate the object copy process. This included both scenarios copying an object when object with same key is already present in the bucket as well as those when the object with same key is not present on bucket. These tests were conducted for both object having size less than multipart threshold and one with greater than multipart threshold

@rakshil14-2 rakshil14-2 marked this pull request as ready for review July 14, 2025 20:30
Copy link
Copy Markdown
Contributor

@aemous aemous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, very nice test coverage!

I requested some changes, most of them are minor. I had one concern with how we are handling copies of 0 byte objects with no-overwrite.

Comment thread awscli/s3transfer/copies.py
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread tests/functional/s3/test_cp_command.py Outdated
Comment thread tests/functional/s3/test_cp_command.py Outdated
Comment thread tests/functional/s3/test_cp_command.py Outdated
Comment thread tests/functional/s3/test_mv_command.py Outdated
Comment thread tests/functional/s3/test_mv_command.py Outdated
Comment thread tests/functional/s3/test_mv_command.py Outdated
Comment thread tests/functional/s3/test_mv_command.py Outdated
Comment thread tests/functional/s3/test_mv_command.py Outdated
@rakshil14-2 rakshil14-2 force-pushed the no_overwrite_feature_for_copy_operation branch 3 times, most recently from 71f54ae to ee0b977 Compare July 18, 2025 21:50
@aemous aemous self-requested a review July 21, 2025 20:07
Copy link
Copy Markdown
Contributor

@aemous aemous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, a couple minor requests, and we'll discuss potentially using LIstObjectsV2 instead of HeadObject offline.

Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
@rakshil14-2 rakshil14-2 requested a review from aemous July 21, 2025 22:38
Copy link
Copy Markdown
Contributor

@aemous aemous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rakshil14-2 rakshil14-2 force-pushed the no_overwrite_feature_for_copy_operation branch from 89dcfbd to 79e2504 Compare July 22, 2025 16:25
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/manager.py
Comment thread awscli/customizations/s3/results.py
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
Comment thread awscli/s3transfer/copies.py Outdated
@rakshil14-2 rakshil14-2 force-pushed the no_overwrite_feature_for_copy_operation branch from f39bcd6 to 039f4b6 Compare July 22, 2025 20:56
@rakshil14-2 rakshil14-2 requested a review from aemous July 23, 2025 22:46
Comment thread awscli/customizations/s3/s3handler.py Outdated
Copy link
Copy Markdown
Member

@kdaily kdaily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start! I think the logic makes sense. I think that the function names and documentation could be clarified a bit.

Also, see the suggestion about where the check is determined. There is an existing list of warning handlers that is used to skip files - could the logic be handled there, since it only needs the FileInfo object to determine?

Also, I noticed that there is a "flicker" in the terminal output when skipping a file with this. We might need to check how the progress status is updated in this case.

Comment thread awscli/customizations/s3/s3handler.py Outdated
updated linting changes

Handling Zero byte edge case

Fixed Exception type

Updated doc string

Updated docs string

Fixed doc string

Update transfer manager for copy operation
improved test case and format

Updated test cases

Fixed edge case for zero bytes

Update warning handler
@rakshil14-2 rakshil14-2 force-pushed the no_overwrite_feature_for_copy_operation branch from 211e9e4 to 75678ed Compare July 25, 2025 19:29
Copy link
Copy Markdown
Contributor

@aemous aemous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I made one non-blocking formatting-related comment.

Comment thread awscli/s3transfer/copies.py
@aemous aemous merged commit 2493f8b into aws:s3-no-overwrite Jul 25, 2025
45 checks passed
rakshil14-2 added a commit to rakshil14-2/aws-cli that referenced this pull request Jul 25, 2025
kdaily pushed a commit that referenced this pull request Jul 29, 2025
kdaily pushed a commit that referenced this pull request Jul 29, 2025
kdaily pushed a commit that referenced this pull request Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants