Repository navigation
feat: make allowOverwrite: false atomic and add --no-overwrite to the CLI - #423
Conversation
[Medium impact] The PR appears safe to merge. SummaryThis PR makes create-only uploads atomic and adds
No new actionable issues found. designcode declined the previous Reviews (3) · Last reviewed commit: "feat(cli): add --no-overwrite to objects..." · Reviewed by Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5860ab3. Configure here.
5860ab3 to
3006232
Compare
put, client upload and completeMultipartUpload send If-None-Match: * when allowOverwrite is false, so a concurrent writer can't be overwritten between the HEAD check and the upload. A 412 maps to "File already exists". Also fixes client upload ignoring allowOverwrite, client multipart reporting success on a failed completion, and put leaving parts behind on large failed uploads. Refs: TIG-11251 Assisted-by: Claude Opus 5.5 via Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs: TIG-11251 Assisted-by: Claude Opus 5.5 via Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3006232 to
f71a5ae
Compare

Summary
put(..., { allowOverwrite: false })did a HEAD check and then an ordinary upload, so a concurrent writer could create the object in between and be silently overwritten. The CLI had no create-only option at all.Fixes TIG-11251.
SDK (
@tigrisdata/storage)putsendsIf-None-Match: *whenallowOverwriteis false. lib-storage copies the params into both single-part PutObject and CompleteMultipartUpload, so this holds at any size. A 412 maps to the existingFile already existserror. The HEAD check stays as a fast fail before any bytes are sent.completeMultipartUploadgets anallowOverwriteoption with the same header and error.lib/object/overwrite.ts, which has no AWS SDK imports, so the browser client can use them.Bugs fixed along the way:
upload()declaredallowOverwritebut ignored it. Single-part uploads now setIf-None-Match: *on the presigned PUT. Multipart uploads sendallowOverwrite: falsetohandleClientUpload, which passes it tocompleteMultipartUpload.handleClientUpload's result as JSON with a 200, and the client never checkederror.putleft parts behind when an upload over 5 MiB failed withoutmultipartset (lib-storage goes multipart on its own). It now always aborts.CLI (
@tigrisdata/cli)tigris objects put --no-overwrite: fails witht3://bucket/key already exists (--no-overwrite).tigris cp --no-overwrite(local to remote): a single file fails the same way.-rand wildcard copies skip existing keys, printSkipped …, and end withUploaded N file(s), skipped M existing; JSON output gets askippedcount. Downloads and remote-to-remote copies reject the flag.cpare merged into one helper.Notes
handleClientUploadis upgraded. An older server ignores the field.allowOverwrite: falseadd anIf-None-Matchrequest header, which triggers a CORS preflight. The bucket's CORS rules must allow that header.Tests
put.test.ts: a real S3Client with an in-memory transport checks the header on single-part PUT and on multipart completion, the 412 mapping, and abort on failure. 7 of the 10 fail without the fix.upload/client.test.tsandupload/server.test.ts: header, 412 mapping, the completion error in the response body, and the handler pass-through.completeMultipartUploaddirectly against the gateway, one over an existing object (refused, original content intact) and one on a new key (succeeds).putwould stop at HEAD first, which is why they bypass it. They skip without access keys, so CI is their first run against the gateway.cli/test/lib/no-overwrite.test.ts: the flag parsed through Commander for both commands, skip and fail behaviour, JSON output, and rejection for downloads.🤖 Generated with Claude Code
Note
Medium Risk
Changes core upload/complete paths and error handling; behavior shifts for concurrent writes and multipart failures, though guarded by tests and backward-compatible defaults.
Overview
Storage SDK makes create-only uploads race-safe: when
allowOverwriteisfalse,put, browserupload, andcompleteMultipartUploadsendIf-None-Match: *(with HEAD still as a fast path), map 412 toFile already exists, and abort multipart uploads on that conflict or other failures so parts are not left behind. The clientuploadpath now honorsallowOverwriteand surfaces completion errors from JSON responses;handleClientUploadforwards the flag and serializes errors for the browser.CLI adds
--no-overwriteontigris objects putand local-to-remotetigris cp(wired toallowOverwrite: false). Single-file uploads fail with a clear message; recursive/wildcard copies skip existing keys and report counts (including JSONskipped). Refactors batch uploads viauploadBatchand closes file streams when uploads are skipped.Docs, changesets, and unit/integration tests cover headers, CLI behavior, and gateway enforcement.
Reviewed by Cursor Bugbot for commit f71a5ae. Bugbot is set up for automated code reviews on this repo. Configure here.