Skip to content

feat: make allowOverwrite: false atomic and add --no-overwrite to the CLI - #423

Merged
designcode merged 2 commits into
mainfrom
aibrahim/tig-11251-make-allowoverwritefalse-atomic-via-if
Nov 19, 2026
Merged

designcode merged 2 commits into
mainfrom
aibrahim/tig-11251-make-allowoverwritefalse-atomic-via-if

Conversation

@designcode

@designcode designcode commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

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)

  • put sends If-None-Match: * when allowOverwrite is false. lib-storage copies the params into both single-part PutObject and CompleteMultipartUpload, so this holds at any size. A 412 maps to the existing File already exists error. The HEAD check stays as a fast fail before any bytes are sent.
  • completeMultipartUpload gets an allowOverwrite option with the same header and error.
  • The shared message and 412 check live in lib/object/overwrite.ts, which has no AWS SDK imports, so the browser client can use them.

Bugs fixed along the way:

  • Client upload() declared allowOverwrite but ignored it. Single-part uploads now set If-None-Match: * on the presigned PUT. Multipart uploads send allowOverwrite: false to handleClientUpload, which passes it to completeMultipartUpload.
  • Client multipart reported success when completion failed. The documented route returns handleClientUpload's result as JSON with a 200, and the client never checked error.
  • put left parts behind when an upload over 5 MiB failed without multipart set (lib-storage goes multipart on its own). It now always aborts.

CLI (@tigrisdata/cli)

  • tigris objects put --no-overwrite: fails with t3://bucket/key already exists (--no-overwrite).
  • tigris cp --no-overwrite (local to remote): a single file fails the same way. -r and wildcard copies skip existing keys, print Skipped …, and end with Uploaded N file(s), skipped M existing; JSON output gets a skipped count. Downloads and remote-to-remote copies reject the flag.
  • The duplicated wildcard and directory upload loops in cp are merged into one helper.

Notes

  • Client multipart is only create-only once the server running handleClientUpload is upgraded. An older server ignores the field.
  • Single-part client uploads with allowOverwrite: false add an If-None-Match request 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.ts and upload/server.test.ts: header, 412 mapping, the completion error in the response body, and the handler pass-through.
  • Integration: two tests drive completeMultipartUpload directly against the gateway, one over an existing object (refused, original content intact) and one on a new key (succeeds). put would 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 allowOverwrite is false, put, browser upload, and completeMultipartUpload send If-None-Match: * (with HEAD still as a fast path), map 412 to File already exists, and abort multipart uploads on that conflict or other failures so parts are not left behind. The client upload path now honors allowOverwrite and surfaces completion errors from JSON responses; handleClientUpload forwards the flag and serializes errors for the browser.

CLI adds --no-overwrite on tigris objects put and local-to-remote tigris cp (wired to allowOverwrite: false). Single-file uploads fail with a clear message; recursive/wildcard copies skip existing keys and report counts (including JSON skipped). Refactors batch uploads via uploadBatch and 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.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This PR makes create-only uploads atomic and adds --no-overwrite to CLI uploads.

  • allowOverwrite: false protects SDK writes from concurrent overwrites.
  • Browser uploads now keep existing objects when overwrite is disabled.
  • CLI uploads can skip or reject existing objects with --no-overwrite.

No new actionable issues found. designcode declined the previous stdout.at(-1) change because the CLI targets ES2022, existing tests use it, and tests run on Node 22+. The other previous concerns are addressed in the current code.

Reviews (3) · Last reviewed commit: "feat(cli): add --no-overwrite to objects..." · Reviewed by Greptile

Comment thread packages/cli/src/lib/cp.ts Resolved
Comment thread packages/cli/src/lib/cp.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

@designcode
designcode force-pushed the aibrahim/tig-11251-make-allowoverwritefalse-atomic-via-if branch from 5860ab3 to 3006232 Compare November 18, 2026 17:39
designcode and others added 2 commits November 19, 2026 10:18
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>
@designcode
designcode force-pushed the aibrahim/tig-11251-make-allowoverwritefalse-atomic-via-if branch from 3006232 to f71a5ae Compare November 19, 2026 16:18
@designcode
designcode merged commit 61852fd into main Nov 19, 2026
3 checks passed
@designcode
designcode deleted the aibrahim/tig-11251-make-allowoverwritefalse-atomic-via-if branch November 19, 2026 16:27
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.

2 participants