Skip to content

fix(services/cos): honor if_not_exists on multipart uploads - #8043

Open
aysha-afrah26 wants to merge 1 commit into
apache:mainfrom
aysha-afrah26:cos-multipart-if-not-exists
Open

fix(services/cos): honor if_not_exists on multipart uploads#8043
aysha-afrah26 wants to merge 1 commit into
apache:mainfrom
aysha-afrah26:cos-multipart-if-not-exists

Conversation

@aysha-afrah26

Copy link
Copy Markdown

Which issue does this PR close?

None

Rationale for this change

COS advertises write_with_if_not_exists, and any write larger than write_multi_min_size (1 MiB) goes through the multipart writer instead of a single PutObject. On the simple path cos_put_object_request sets x-cos-forbid-overwrite when the caller asks for if_not_exists, but the multipart initiate and complete requests never set it, so once a write crosses the multipart threshold the overwrite guard is dropped and an existing object is replaced while the caller still gets Ok. I noticed this while reading the recent OSS fix in #8041, which is the same shape: the header has to ride on both InitiateMultipartUpload and CompleteMultipartUpload. Tencent documents x-cos-forbid-overwrite as a supported header on InitiateMultipartUpload and lists the cos:x-cos-forbid-overwrite condition key against both InitiateMultipartUpload and CompleteMultipartUpload, so setting it on only one of them is not enough. The fix threads OpWrite into cos_complete_multipart_upload and sets the header on both requests when if_not_exists() is true. Small single-shot writes are unaffected since they already carried the header.

What changes are included in this PR?

  • Set x-cos-forbid-overwrite: true on cos_initiate_multipart_upload and cos_complete_multipart_upload when args.if_not_exists() is set.
  • Pass OpWrite through to cos_complete_multipart_upload from the writer's complete_part.

No new test is added: test_writer_write_with_if_not_exists already drives the chunked writer path for any service with write_with_if_not_exists and write_can_multi, so it covers COS and fails against a real bucket on the current code.

Are there any user-facing changes?

A large if_not_exists write to COS (over write_multi_min_size) now returns ConditionNotMatch when the object already exists, matching the behavior of small writes. Code that relied on the previous silent overwrite for large objects will now see the precondition enforced.

AI Usage Statement

@aysha-afrah26
aysha-afrah26 requested a review from Xuanwo as a code owner August 9, 2026 16:52
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. releases-note/fix The PR fixes a bug or has a title that begins with "fix" labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant