Repository navigation
feat(fs): --overwrite replaces a server-side copy; reject scheme-spelled local paths - #100
Conversation
…eme-spelled local paths Follow-ups from #99, all in one change. --overwrite for a remote to remote copy. The service inserts a new node at the destination and the unique path index rejects a duplicate, so asking it to copy onto an existing path returns 500 backend unavailable. ti now copies the source to a sibling <target>.ti-tmp-<rand> path and moves it onto the destination: the rename replaces the target in one datastore transaction, a failed copy leaves the destination untouched, and a failed move removes the staging path on a best-effort basis. The probe still refuses without the flag, and a resolved destination that is itself a directory is refused with fs.remote_copy_target_is_directory. Uploads and downloads keep their single native overwrite call. The directory rule now lives in one resolver shared by the probe and the replace, so the two cannot disagree about the path a copy writes. Scheme-spelled local paths. The companion resolves file:///path itself, while ti probes local destinations as literal paths, so --to-local file:///path passed the probe and still overwrote the parsed file. --from-local and --to-local now reject a location scheme with fs.local_path_scheme_unsupported (a single-letter scheme is a Windows drive letter and is left alone). Also: --overwrite help and README say what each direction does, and the live step copies onto an existing remote path both with and without the flag.
mornyx
left a comment
There was a problem hiding this comment.
Review summary
This change makes --overwrite replace an existing remote destination for a server-side copy (copy to a sibling <destination>.ti-tmp-<8 hex>, then fs mv onto the destination) and refuses scheme-spelled local paths on --from-local/--to-local. The mechanism is sound against the pinned service: its copy cannot replace (the duplicate is 500 backend unavailable), and the rename is one transaction (RenameFileReplacingTarget), so a reader sees either the old file or the complete new one; uploads and downloads keep their single native call. The probe and the replace now share one destination resolver, and a base-vs-head transcript of 56 copy shapes shows no change for any non---overwrite case. Under a strict maintainability bar nothing here is merge-blocking, but five things should be fixed before merge: the refusal users meet without the flag now contradicts the feature, a failed replace can leave the staging file behind silently while the README states the wrong permission, a README clause this PR rewrites promises remote symlink resolution the service does not have, the published reference page still has the old text, and the new tests pin the call sequence rather than the outcome.
What looks good
- One destination resolver (
resolveDrive9RemoteCopyDestination) feeds both the probe and the replace, so they cannot disagree about the path a copy writes. - Copy to a private sibling plus the service's one atomic rename, instead of delete-then-copy: a failed copy never touches the destination, and a failed move removes the staging path when the token allows it.
- The scheme check is conservative in the right direction: drive letters, opaque
a:b, UNC paths, whitespace and colons in later segments are left alone, and thefile:///pathprobe bypass from #99 is closed with an actionable message. - The new tests live in a dedicated file with descriptive names.
Should fix (non-blocking, strong)
1. The refusal still says a server-side copy cannot replace
internal/fs/drive9_companion.go:784 (comment at :766-771)
Without the flag the message is … already exists; a server-side copy does not replace an existing path, so copy to a new path or delete it first, and the comment still says --overwrite "would only turn a clear refusal into a server error". Both are false after this change, and "delete it first" is the non-atomic path the staged rename was added to avoid. The sentence is pinned in four places: internal/fs/drive9_copy_target_probe_test.go:51-55 (the test fails if the message offers --overwrite), :131, e2e/live_test.go:1340, and the assertion this PR adds at :1358.
Fix: give this direction the same advice as uploads and downloads (… already exists; pass --overwrite to replace it), keep the "is the source path" sentence, and update the comment and the four assertions.
2. A failed replace can leave the staging file behind without saying so, and the README names the wrong permission
internal/fs/drive9_companion.go:511 (and :507-513), README.md:192
On the pinned service the rename needs delete on its source, the staging sibling, and write on the destination (pkg/server/server.go:4171); rm needs delete as well (:3996); a scope matches a path exactly or by prefix/ (fs_authorization.go:156-164). Two consequences the text does not describe:
- "the file-system token needs delete on the destination as well as write" names the wrong path. A grant scoped to the destination file itself (
…:read,write,delete) is refused at the staged copy, because the sibling lies outside it. The requirement is read on the source and on the destination, and write and delete in the destination's directory. - With read and write but no delete on the directory (the scoped-token example in
AGENTS.mdis exactly that shape), the staged copy succeeds, the move is refused, the cleanuprmis refused too and its error is discarded. One<destination>.ti-tmp-<8 hex>stays per attempt, the user sees only the move's error, and nothing names the file. "a failed move removes the temporary path" is false for that key.
The same silent leftover arises when the staged copy itself fails after the service created the node: an ambiguous failure, then the transient retry meets the duplicate (500 backend unavailable), and no cleanup runs because it only follows a failed move. The PR description says two limits are "documented rather than papered over"; that holds for the description only, since the README has neither the listing note nor the staging name.
Fix: reword the two README sentences to state the real requirement and that the staging file stays without delete; when the cleanup fails, return an error that names the staging path and the ti fs delete-file --path … that removes it; document the .ti-tmp- suffix so a leftover can be found.
3. The README promises remote symlink resolution the service does not have
README.md:192
"a directory destination (an existing directory, a trailing separator, the root, or a symlink resolving to a directory) receives dir/<base(source)>" is true for local destinations only. The pinned service has no symlink resolution: a remote symlink is a node whose payload is the target path, and HEAD reports the link itself as a non-directory (pkg/server/server.go:3908). So ti's probe and the companion both treat --to-remote /lt as a file path, and with --overwrite an upload overwrites the link's own payload (checked for a small file): the link is lost and nothing lands in the directory. The clause predates this PR, but this PR rewrites the sentence and presents the paragraph as the copy contract.
Fix: restrict "or a symlink resolving to a directory" to --to-local, and say that a remote symlink destination is the link itself. If the documented behavior is wanted, that is a separate change (resolve the link before the copy).
4. The published reference page still documents the old --overwrite
docs/pingcap-docs/docs/ai/ti/reference/commands/fs/ti-fs-copy-file.md:52 (submodule a8e00c35)
It says "--overwrite: Replace an existing destination file." — the sentence this PR replaces in the flag help — and has neither the staged rename nor the two new refusals. AGENTS.md requires the matching ti page to follow published behavior, and "docs match the code" is one of the three goals in the description.
Fix: update the page and bump the submodule in this change, or name it as a follow-up in the PR description.
5. The new tests pin the call sequence, not the outcome
internal/fs/drive9_copy_overwrite_test.go:143
TI_FAKE_DRIVE9_MV_FAIL covers only "move fails, rm succeeds". Not covered: a cleanup that fails (the error the user actually sees, and whether the staging path is named), a staged copy that fails (no mv, no rm), and the message text of the two new codes. The live step is the only place the real service is exercised and does not check that no staging entry remains; the description reports that from a replay outside the suite.
Fix: add fake-companion switches for a failing rm and a failing staged cp and assert on them; in the live step, list rootPath after the overwrite and assert that no entry contains .ti-tmp-.
Nits
- Self-copy with
--overwritereports success (internal/fs/drive9_companion.go:489).--from-remote /a --to-remote /a --overwrite, directly or through a directory destination, now stages a copy of the file and renames it onto itself, then reportscopied. Nothing is lost, but it reads as a refresh while the same shape without the flag is refused as "is the source path". ReusesameDrive9RemotePath(source, destination.Path)and refuse. - The
:-prefixed spelling still bypasses the local probe (internal/fs/drive9_companion.go:603).--to-local :/xpasses (url.Parsefails on the leading colon), skips the local probe, and reaches the companion as a drive9 path, so the "download" becomes a server-side copy into/x(it cannot overwrite anything, andmainbehaves the same). The comment at:573-578says such spellings are rejected instead; reject a leading:too. Also worth one clause in the README or the commit: the check now refuses every registered scheme, object-store URIs (s3://,gs://, …) included, which were passed through before. - Unreachable guard (
internal/fs/drive9_companion.go:1935-1939).drive9CopyArgsForTarget's "a retargeted copy must be a remote to remote copy" cannot fire, since its only caller runs afterisDrive9ServerSideReplace, and it has no test; drop it or test it. If the staged argv is ever built at the call site instead, keep the--tag/--descriptionpass-through: the staged copy carries them today and the companion refuses them for a server-side copy, so dropping them silently would make the same command succeed with an existing destination and fail without one. (Follow-up, not for this PR: the copy family is about 500 lines inside a 2,194-line file and would be easier to maintain in its own file.) - Live assertion attribution (
e2e/live_test.go:1365). The mismatch is found onoverwriteRead.stdoutbut reported throughoverwriteCopy.fail(...), so the diagnostic prints the copy's successful output; useoverwriteRead.fail(...)with got and want.
Recommendation
Comment. No merge-blocking defect was found; the five items above should be fixed before merge.
- Without the flag, a server-side copy now gets the same advice as every other direction (pass --overwrite to replace it), because this change makes that advice true; the 'delete it first' advice and the comment that said --overwrite could only turn the refusal into a server error are gone. The four assertions that pinned the old sentence are updated. - A replace that cannot clean up its staging file no longer fails silently: the error names the staging path and the ti fs delete-file command that removes it, and a failed staged copy runs the same cleanup instead of leaving the node behind. README states the real permission requirement (read on source and destination, write and delete in the destination's directory), that the staging sibling is visible in a listing, and how to find a leftover by its .ti-tmp- suffix. - README no longer promises remote symlink resolution: only a local destination resolves a directory symlink, and a remote link destination is the link itself. The scheme paragraph now names the drive9 ':' spelling and says every scheme the companion knows is refused. - --overwrite on a shape that resolves to the source is refused instead of staging a copy of a file onto itself. - New tests cover a failing cleanup (message names the staging path and the command), a failing staged copy (cleanup runs, no move, the copy error is what surfaces), the self-copy refusal on both spellings, the retarget guard, and the ':' spelling. - The live step lists rootPath after the replace to prove no .ti-tmp- entry survives, and reports a byte mismatch through the read command.
|
All five items and the nits are addressed in 1. The refusal now offers the flag. 2. The staging leftover is no longer silent, and the README states the real requirement. A failed cleanup returns A failed staged copy now runs the same cleanup instead of skipping it, and keeps the copy error as the one the caller sees. The README says: read on source and destination, write and delete in the destination's directory (a rename deletes its staging source), that a grant scoped to the destination file alone is refused at the staged copy, that the sibling is briefly visible in a listing, and that a leftover is found by its 3. Remote symlinks. The clause is now scoped: only a local destination resolves a directory symlink; a remote destination has none, because the service treats a link as a file whose payload is the target path, so a remote link destination is the link itself. 4. The published page is named as a follow-up below rather than bumped here: 5. Tests pin outcomes, not just the call sequence. New cases: Nits. Self-copy with Follow-up (docs). Local: |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
The second commit points the --overwrite=false refusal at the flag for every direction, reports a staging file it could not remove, cleans up after a failed staged copy, refuses a self-replace, rejects :-prefixed local values, and rewrites the README paragraph. On this head the earlier items are resolved, with one partial point left (a leftover after a failed staged copy is still unnamed) and the published page kept as the agreed follow-up. No merge-blocking defect was found, and the replace itself is unchanged and still correct against the pinned service. The rewrite of two helpers introduced two should-fix inaccuracies, each reproduced with a built binary: one refusal now gives false advice for an upload shape, and the staging cleanup misreports on three paths.
Resolved since the last review
- The refusal offers
--overwritein every direction and keeps the "is the source path" sentence; the four assertions follow. - A failed move whose cleanup fails now returns
fs.copy_staging_left_behindwith the staging path and the removal command, and the README states the real permission requirement, the listing visibility and the.ti-tmp-suffix. - The symlink clause is scoped to local destinations.
--overwriteon a shape that resolves to the source is refused before any write: the same path, a directory destination with or without a trailing separator, the root and..spellings all hold.:-prefixed local values are rejected exactly where the companion reads them as drive9 paths, with the same code and exit code as the scheme case.- The retarget guard has a test and the
--tag/--descriptionpass-through is kept; the live step lists the directory after the replace and reports through the read command.
What looks good
fs.copy_staging_left_behindis the right shape for this failure: it keeps the move error as the cause and tells the user which file to remove.- The new tests assert on the message, not only on the argv, for the cleanup failure and the self-copy refusal.
- The fix commit is small and stays inside the copy family.
Should fix (non-blocking, strong)
1. An upload whose local absolute path equals the remote path is refused as "is the source path"
internal/fs/drive9_companion.go:802
remoteTargetExistsError no longer branches on the source kind, so the same-path check compares the raw --from-local string with the remote path. ti fs copy-file --from-local /data/x.csv --to-remote /data/x.csv without --overwrite (remote file present) now answers remote target "/data/x.csv" is the source path; copy to a different path instead. On main and on the previous head it answered … already exists; pass --overwrite to replace it. The local file is not a remote source path, the sentence is false, and the advice that would have worked is gone. Only an absolute local path can trigger it, and --overwrite still works. The same edit leaves sourceKind unused (:801-806) and repeats the sentence at :502-504.
Fix: gate the comparison on sourceKind == drive9CopySourceRemote inside remoteTargetExistsError, call that helper from drive9CopyReplacingRemoteTarget instead of repeating the sentence, and add an upload case whose local absolute path equals the remote path to TestDrive9CopyUploadRejectionStillOffersOverwrite.
2. The staging cleanup misreports on three paths
internal/fs/drive9_companion.go:531
discardDrive9CopyStaging returns the raw fs rm error, and its two callers read it differently.
- Move applied, answer lost. If the service committed the rename and the answer was lost,
fs rm <staging>answers not found and ti exits withfs.copy_staging_left_behind: it says the replace failed and points at a delete command for a path that no longer exists, while the destination already holds the new bytes. The previous head returned the move error alone. The helper's comment says "removed" and "never existed" are treated alike; this caller says the opposite. - Failed staged copy without
delete. At:513the cleanup result is discarded. When the staged copy created its node and then failed, and the token cannot delete, one staging file stays per attempt and the ti error is only the copy's. The README now says the error names the staging path whenever the replace fails and the token cannot delete. - Stray output. The cleanup runs uncaptured and the runner streams companion stderr (
internal/fswrap/runner.go:95-98), so a staged copy that failed before creating anything now prints an extrafs rmerror line (… not found) between the copy's error and ti's. The previous head printed one error.
The fake companion cannot show any of this: its rm succeeds on any path and its only failure text is permission denied (internal/fs/drive9_fake_companion_test.go:248), so TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy pins the rm argv against a behavior the service does not have.
Fix: have the helper report three outcomes (removed, already absent through isDrive9NotFound, failed) and run the rm captured, so its raw line reaches the user only when ti decides it matters; attach the same leftover note to the primary error at both call sites; when the move failed and the staging path is already absent, say the move's outcome is unknown and point at ti fs describe-file --path <destination>. Two fake switches (rm answers not found; mv applied then failed) with assertions on the messages would pin all three.
Nits
- README.md:192, three sentences. "both pass
--overwriteto the companion" is not what happens: ti forwards no such flag; with--overwriteti skips its own probe and the companion's plain write replaces. The directory rule is now stated for local destinations only, but a remote destination follows it for an existing directory, a trailing separator and the root as well; only the symlink clause needed scoping. Andti fs delete-file --path <staging>needs a token withdelete, which is exactly what the "token without delete" case lacks; say so there and in thefs.copy_staging_left_behindmessage. - Stale text after the fix. The doc comment at
internal/fs/drive9_companion.go:486-487still says the staging path is "removed on a best-effort basis". The PR description still carries the first commit's wording ("a failed move removes the staging path on a best-effort basis", "the move needs delete on the destination in addition to write") and lists neither the:rule,fs.copy_staging_left_behind, the new tests, the live listing assertion nor the docs follow-up (which is in a comment).
Recommendation
Comment. No merge-blocking defect was found; the two items above were introduced by the fix commit and should be corrected before merge.
…leanup honestly Two regressions from the previous fix commit, both reproduced with the built binary. The refusal lost its source-kind branch, so a local absolute path that merely spelled the remote destination (--from-local /data/x.csv --to-remote /data/x.csv) was told it was the source path, losing the --overwrite advice that works. The collision sentence now applies only to a remote source, and drive9CopyReplacingRemoteTarget reuses the helper instead of repeating it. The staging cleanup returned the raw fs rm error, which made its two callers misreport: an applied rename whose answer was lost came back as 'staging left behind' pointing at a delete for a path that is already gone, a refused cleanup after a failed staged copy was discarded while the README promised the staging path would be named, and a failed copy that never created the node printed the companion's not-found line. The helper now reports removed/absent/failed, runs captured so its error only reaches the user when ti decides it matters, and both call sites attach the same leftover note; when the move failed but the staging path is gone, the error says the outcome is unknown and points at ti fs describe-file. README: with --overwrite ti forwards no flag, it skips its own probe and lets the companion's plain write replace; the directory rule applies to a remote destination too (only the symlink clause is local-only); the delete-file remedy itself needs delete on the staging path. New tests: upload whose local path spells the destination, unknown outcome after an applied-but-unreported rename, a refused cleanup after a failed staged copy, and the delete permission note in the message.
|
Both regressions are real and both were mine; 1. The refusal lost its source-kind branch.
2. The staging cleanup now reports what happened.
Three new tests pin those paths ( Nits, all taken. README: with
|
mornyx
left a comment
There was a problem hiding this comment.
Review summary
The third commit gates the same-path refusal on a remote source and reuses that helper in the replace path, makes the staging cleanup report removed / absent / failed and run captured, adds fs.copy_outcome_unknown, attaches the leftover note after a failed staged copy, and takes the README and description nits. Both items from the second review are fixed as asked, and the replace itself is correct and unchanged. One thing is still wrong: the cleanup decides whether a staging file exists from the failure text of a single fs rm instead of asking the service, and that inference is wrong in three reproduced cases, two of them regressions against the previous head. No data is lost or corrupted in any reproduced case.
Resolved since the last review
- The same-path refusal applies to a remote source only: an upload whose local absolute path equals the remote path is back to the
mainwording, with a test, and the replace path calls the same helper. - The cleanup runs captured: a copy that created nothing under a token that can delete prints one error and no stray
fs rmline. - A rename that was applied before its answer was lost is reported as
fs.copy_outcome_unknownpointing atti fs describe-file, when thermreaches the service. - A leftover after a failed staged copy is named when the cleanup is refused.
- README: no flag is forwarded, the directory rule covers both destination kinds, the remedy needs
delete; the doc comment and the PR description are rewritten.
What looks good
remoteTargetExistsErroris the single owner of the collision sentence, and nothing else changed for non---overwriteusers.- Capturing the cleanup is the right call, and the leftover message keeps the cause, names the path and states the permission the remedy needs.
fs.copy_outcome_unknownis the right instinct for a rename whose answer was lost.
Should fix (non-blocking, strong)
1. The staging cleanup still infers instead of observing
internal/fs/drive9_companion.go:515 (and :521-531, :552-562)
discardDrive9CopyStaging maps one fs rm attempt to "removed", "absent" or "failed" from its error text, and each caller reports from that. Three reports are wrong on this head, all reproduced with a built binary:
- False leftover under a token without
delete(regression against3c59d583). The service authorizesDELETEbefore it looks the path up, sofs rm <staging>answersfs access deniedwhether or not the file was created. Every staged copy that created nothing - a missing source, a directory source, nowrite, a grant that does not cover the staging sibling - is now reported asfs.copy_staging_left_behind, with a delete command for a file that is not there.README.md:287gives exactly this token as the scoped-token example (--allow /workspace:read,list,write), so for it the report no longer depends on what happened. - A non-JSON 404 reads as "absent" (regression against
3c59d583).isDrive9NotFoundis a substring test, and the companion renders a non-JSON error body asHTTP 404: <body>. A gateway page on thermmakes ti reportfs.copy_outcome_unknown("its staging copy is gone") while the staging file is still there and the destination untouched: a real leftover, unnamed. fs.copy_outcome_unknowndepends on one unretriedrm. If thatrmfails on a transport error right after the move failed, the outcome is "failed" and the user gets the leftover note this commit set out to remove, for a path that is gone while the destination already holds the new bytes.
The same root cause shows on Ctrl+C: the cleanup runs on the cancelled context, cannot start, and an interrupted replace reports a leftover it never looked for.
The second review asked for the leftover note at both call sites. That suggestion did not account for authorize-before-lookup; this item is its correction.
Fix: ask the service whether the staging file is there before trying to delete it. drive9StatTarget already makes that call, retried, on these paths, and needs read, which the destination probe has already used in that directory. Then delete what exists through drive9RunTransientRetry (a 404 is the goal state), keep today's reading of a refused rm only as the fallback for a token whose stat is refused, and run the check on a context that survives cancellation. Once the stat has seen the file, a failed removal is a leftover whatever its text says.
While there, one function that returns the final error would replace the outcome type, the two different dispatches over it and the free-text clause of drive9StagingLeftoverError (:540-567). Both call sites want the same decision: the error the user should see after a failed replace.
Tests (internal/fs/drive9_copy_overwrite_test.go:178): the fake cannot express "refused before the lookup" - its rm outcomes are process-wide switches and its stat answers from a static map - which is how the first case passed the new tests. Give it a small state file (paths created by cp, moved by mv, removed by rm) and a permission set, and pin three things: a staged copy that creates nothing under a token without delete gives the copy error alone; a failed staged copy with rm answering not found prints no stray line; and the failed-move test asserts the move error itself rather than only the absence of the leftover code. A stat-first change needs that stateful fake: against the static one, four of the current tests fail because every staging path answers not found.
Nits
- README.md:192. The paragraph names every other copy error code but neither
fs.copy_staging_left_behindnorfs.copy_outcome_unknown. "(no overwrite flag is forwarded - the companion has none)" is inexact: the pinnedfs cphas-f|--force, honored for object-store URIs only. And the unknown-outcome pointer names only the destination; a server-side copy shares the source's file id, so naming both paths makes thedescribe-filecomparison decisive, and saying that re-running with--overwriteis safe gives the user something to do. - PR description. "a failed staged copy tries to remove the staging file; the copy error remains the one reported" is not what happens when the cleanup is refused (the reported error becomes
fs.copy_staging_left_behind, with the copy error as its cause), and the docs follow-up list omitsfs.copy_outcome_unknown.
Recommendation
Comment. No merge-blocking defect was found; the cleanup item above should be corrected before merge.
The cleanup decided whether a staging file existed from the error text of a single fs rm, and that reading is wrong in three ways the review reproduced: the service authorizes DELETE before it looks a path up, so a token without delete reports every staged copy that created nothing as a leftover; a non-JSON 404 body is matched by the 'not found' substring and turns a real leftover into 'outcome unknown'; and an unretried transport error turns a gone staging file into a leftover note. On Ctrl+C the cleanup inherited the cancelled context and could not start at all. The cleanup now asks the service whether the staging path exists (fs stat, retried) before deleting, treats an absent path as 'nothing to clean', deletes what exists through the transient retry, and keeps the old reading of a refused rm only as the fallback for a token whose stat is refused. It runs on a context that survives cancellation with a 30s bound, and one function now returns the error the user should see, so both call sites share the decision. The messages the review asked for: fs.copy_outcome_unknown names both paths and says re-running with --overwrite is safe; fs.copy_staging_left_behind carries the cause, the staging path, the delete command, the permission it needs and the source. The fake companion gained a stateful mode (paths created by cp, moved by mv, removed by rm, plus delete/stat refused switches), because the static stat map could not express any of the three cases; four of the replace tests now run against it, including a staged copy that creates nothing under a token without delete.
|
Correct on all three counts, and the root cause was mine: I inferred existence from an error string instead of asking the service. The cleanup now:
Your three cases, on the built binary with a stateful stand-in: The fake can express it now. It gained a stateful mode (
You were also right that the static fake would have failed four tests under a stat-first change; that is why the mode exists rather than a patched map. Nits. README now names both
|
mornyx
left a comment
There was a problem hiding this comment.
Review summary
The fourth commit replaces the outcome type and the two dispatches with one function, drive9CopyFailure: it stats the staging path first (retried), removes what exists through the transient retry, keeps the old reading of a refused rm when the stat itself is not answered, and runs on a context that ignores cancellation with a 30 second bound; the two messages are rewritten, the replace tests are rebuilt on a stateful fake, and the README and description nits are taken. The misreports from the third review are fixed for the tokens and sequences that hit them, and an interrupted replace now cleans up. Two things should be fixed before merge, both in what this commit added: when the stat is refused or times out, the fallback still reports a leftover it never saw, and the test rewrite dropped assertions and leaves the fallback and the cancellation fix without a test. No merge-blocking defect was found.
Resolved since the last review
- The scoped token the README documents (
--allow /workspace:read,list,write) now gets the copy error alone when nothing was created, and a named leftover when the staged copy did create the file. - A rename that was applied before its answer was lost is reported as
fs.copy_outcome_unknownwithout depending on anrm; the message names both paths and says re-running with--overwriteis safe. - The removal goes through the transient retry: a first transport error no longer produces a leftover note.
- An interrupted replace cleans up or reports truthfully: Ctrl+C during the staged copy gives the plain copy error with no leftover claim, and Ctrl+C during the move removes the staging file.
- The outcome type and the free-text clause are gone; one function returns the final error for both call sites.
- README names both codes and corrects the flag note; the description's failure bullet and the docs follow-up list are fixed.
What looks good
- Stat-first is the right order for a service that authorizes
DELETEbefore it looks the path up. - The cleanup survives cancellation and is bounded: in the two interrupted replaces I replayed (during the staged copy and during the move) nothing was left behind, no false leftover was claimed, and the command returned in about a tenth of a second.
TestDrive9CopyServerSideOverwriteAppliedMoveLostAnswerand the reworked failed-move test assert on the message the user sees, and the applied-but-unreported rename is expressed as state rather than as a static switch.
Should fix (non-blocking, strong)
1. The fallback for a refused or unanswered stat still states a leftover it never saw
internal/fs/drive9_companion.go:544
When the stat of the staging path is refused or fails, the !state.known branch reads one fs rm answer, and its default arm returns fs.copy_staging_left_behind with "the staging copy … could not be removed". That is a claim that the file exists - the one thing this branch could not establish:
- The stat is refused for a token whose
readcovers the destination file but not its directory (the grant the README itself names as insufficient), and it fails for any token while the backend answers 500. In both cases the staged copy has already failed without creating a node, so the leftover is false on every attempt and the copy error the user needs is demoted to a parenthetical cause. - After a failed move the same arm can name a leftover that is gone: rename applied, answer lost, then stat 500 and
rm500, while the destination already holds the new bytes. - When the 30 second bound expires during the stat, the
rmnever starts, and the message blamesfs rm … context deadline exceeded.
The README's new parenthetical ("fs.copy_staging_left_behind (the staging file is still there and the error names it)") repeats the claim, and the paragraph does not describe the fallback. Keeping a fallback for a refused stat was the third review's own suggestion; the problem is only that it states an outcome where it has a possibility.
Fix: treat "could not look" as its own outcome instead of folding it into "present". When the stat was refused or timed out and the removal then fails, say that ti could not check the staging path (with the stat error) and that a .ti-tmp- entry in that directory, if one is listed, should be deleted; and stop promising in the README that the file is there. Check checkCtx.Err() before the rm, so an expired bound is reported as a timeout rather than as a refused removal. Do not trade the old inference for a new one drawn from the refusal text. The "not found" text match itself (a gateway page on the stat or on the rm) needs a failure and then a page on the very next call; that is follow-up material, not for this PR.
2. The test rewrite dropped assertions and leaves the new behavior untested
internal/fs/drive9_copy_overwrite_test.go:286
TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopyused to assert "nomvafter a failed staged copy" and "the staging path was removed". It now asserts only that the error isfs.companion_failed, which is also what no cleanup at all returns. The PR description still lists "no move, cleanup attempted" for it.- The fallback and the cancellation fix are uncovered: on this head, making the fallback unreachable, or replacing
context.WithoutCancel(ctx)withctx, leaves the wholeDrive9Copyfamily green. - The fake cannot express the refusal that reaches the fallback:
TI_FAKE_DRIVE9_STAT_DENIEDis one global switch, so throughCopyFileit refuses the destination probe first, and no test sets it.TI_FAKE_DRIVE9_RM_NOT_FOUNDandTI_FAKE_DRIVE9_RM_FAILhave no user left, and the staticmv,rmand staged-cpbranches of the fake are unreachable. newStatefulCopyServicereturns the state directory and no test reads it, so the tests still pin thermargv rather than the final set of paths - the thing the stateful mode was added for. The new "the source is …" clause of the leftover message is not asserted either.
Fix: read the state file after each scenario (the staging path is gone after the two cleans-up tests; only the destination remains after the applied-move test). Add a test that cancels the context before the cleanup and asserts that stat and rm still run and the original error comes back. Give the fake a read scope so the destination probe succeeds and the staging stat is refused, and pin the fallback with it. Delete the unused switches and the dead branches.
Nits
- Signals during the cleanup (
internal/fs/drive9_companion.go:534). The cleanup ignores not only the first Ctrl+C, which is the point, but every later signal: SIGINT and SIGTERM stay captured until ti exits and nothing in the cleanup reads them. With a stat that does not answer, ti sits out the full 30 seconds whatever the user sends, andkill <pid>does not end it (reproduced: three SIGINTs and a SIGTERM ignored until the bound). Wait oninterrupt.Signals(checkCtx)alongside the companion calls and stop the cleanup on the next signal, reporting that the staging path was not checked. - Shape of
drive9CopyFailure(:540-590). Thefs.copy_outcome_unknownmessage is built twice, verbatim (:540,:553);fs rmis invoked twice with the same argv (:547,:561);drive9StagingLeftoverErrortakes a positionalmoveFailed boolwhose only use is to choose between two openings; and a type and a method are both nameddrive9StagingState(:574,:579), sostate := s.drive9StagingState(…)reads as a conversion. One look, one removal and one helper for the unknown case would remove all of it. - Text (
README.md:192). The permission sentence leaves outreadin the destination's directory, which the staged copy's ownHEADon the staging sibling needs - that is the actual reason "a grant scoped to the destination file alone is refused at the staged copy". "the pinnedfs cp" is review vocabulary in a user-facing sentence, and "honoured" is the README's only British spelling. In the PR description, the line for…CleansUpAfterFailedStagedCopydescribes the previous head's test, and the failure-handling list has no bullet for the fallback.
Recommendation
Comment. No merge-blocking defect was found; the two items above should be corrected before merge.
The fallback for an unreadable staging path read one fs rm answer and reported 'could not be removed', which states that the file exists - the one thing that branch could not establish. It fires for a token whose read covers the destination but not its directory, for a backend error during the stat, for an expired 30s bound and for a second interrupt, and each of those turns a clean failure into a false leftover with the copy error demoted to a parenthetical cause. The cleanup now has three outcomes: absent (nothing to clean), present (remove it, and a refused removal is a real leftover), and unobserved. The unobserved case reports fs.copy_staging_unchecked, carries the stat failure, and says which .ti-tmp- entry to look for instead of claiming one; an expired bound is reported as a timeout rather than as a refused removal. It also waits on interrupt.Signals, so a second Ctrl+C stops the cleanup instead of being captured until the bound. Tests: the path set is read after each scenario (the staging file is gone after the two cleans-up cases, only the destination remains after the applied-move case), a cancelled copy still stats and removes the staging file, and the unreadable-staging fallback is pinned with a fake that denies stat for the staging sibling only. Mutating context.WithoutCancel(ctx) back to ctx, or making the fallback unreachable, now fails those two tests. The fake drops the switches and branches that no longer have a caller. README: read in the destination's directory is part of the requirement, the companion command is named as such, and the three failure codes are described by what they observed.
|
Both items are fixed in 1. The fallback no longer states an outcome it could not observe. The cleanup now has three outcomes:
An expired bound is checked before the removal and reported as The cleanup also waits on 2. Tests restored and extended, and the new behaviour is covered. The fake state file is now read after each scenario: after the two cleans-up cases only the destination remains, after the applied-move case the path set is exactly the destination, and
I checked that coverage by mutation: replacing Nits. README:
|
mornyx
left a comment
There was a problem hiding this comment.
Review summary
The fifth commit replaces the "stat refused, so read one fs rm answer as a leftover" fallback with three outcomes that say what ti observed (absent, present, unobserved as fs.copy_staging_unchecked), moves the cleanup body into a goroutine so a signal can stop it, and restores the tests. Both items from the fourth review are resolved, and every branch that runs without a signal reports the truth. But the new signal wait is wired to the command's own signal channel, which still holds the signal that stopped the copy: on the first Ctrl+C or SIGTERM the cleanup is abandoned without one companion call, the staging file stays, and a move that had committed is no longer reported as fs.copy_outcome_unknown. That undoes the round-3 fix on the path it was about, contradicts the README, the description and the commit message, and no test can see it.
Resolved since the last review
- A refused, failed or expired stat is no longer reported as a leftover:
fs.copy_staging_uncheckedsays ti could not determine whether the staging file exists, carries the stat and removal answers, and an expired bound is reported as a timeout. - The two dropped assertions are back and assert the final path set; the fallback and the cancellation fix are pinned (both fourth-review mutations now fail a test, and so does skipping the removal).
- A cleanup whose stat does not answer is stopped by a signal that arrives while it runs, instead of holding the command for 30 seconds.
- README:
readin the destination's directory, the companion command named instead of review vocabulary, "honored", and the three codes described.
What looks good
- The three outcomes are named for what ti observed, and every branch that runs without a signal is truthful.
- The fake's
TI_FAKE_DRIVE9_STAT_DENIEDis path-aware now, which is what made the unchecked case testable at all. - The unknown-outcome message is built once, and the
drive9StagingStatename clash is gone.
Blocking (please address before merge)
1. On the first Ctrl+C or SIGTERM the cleanup no longer runs
internal/fs/drive9_companion.go:546
drive9CopyFailure selects on interrupt.Signals(checkCtx), and the comment says the first signal "was already used to cancel the copy" and this one is a further signal. It is the same signal. checkCtx derives from the command's context through context.WithoutCancel, so it carries the same channel: the one interrupt.NotifyContext created for the whole process (cmd/ti/main.go:22). Its goroutine cancels the context and then puts that first signal into the channel (internal/interrupt/context.go:38-41, buffer of two at :30), and nothing on the companion Run path reads it (internal/fswrap/runner.go:82-103; the only other reader is waitStreaming). So when the staged copy or the move fails because of Ctrl+C, a signal is queued, and the select takes the "further signal" branch at once.
Reproduced on this head with one signal (SIGINT and SIGTERM behave the same):
- during the staged copy:
fs stat <destination>,fs cp- nothing else; - during the move:
fs stat,fs cp,fs mv- nothing else, and the staging file stays; - during a move that had already committed: the destination holds the new bytes, and the error only says to look for a
.ti-tmp-entry.fs.copy_outcome_unknownand itsdescribe-fileadvice are gone for this case.
On aa52214a the same inputs ran fs stat and fs rm on the staging path, removed it, and reported fs.copy_outcome_unknown for the committed move. The select does what it says only when the failure had another cause and a signal arrives while the cleanup runs. README.md:192 ("or a second interrupt"), the PR description ("so an interrupted replace still cleans up") and this commit's message ("so a second Ctrl+C stops the cleanup") all describe a behavior the code does not have, and all five messages land. TestDrive9CopyFailureCleansUpOnCancelledContext cancels a plain context, where interrupt.Signals is nil, so the signal case can never fire; replacing the select with return <-done leaves the Drive9Copy family green.
Fix: wait on a channel that cannot contain the signal that failed the copy. The mount code in this package already registers one of its own (internal/fs/fuse_mount.go:96-98, internal/fs/vault_mount.go:60-62): register a fresh channel for the cleanup, so that only a signal delivered after the cleanup started stops it. I checked that on a private copy: one Ctrl+C before the cleanup now runs fs stat and fs rm on the staging path and removes it, a committed move is reported as fs.copy_outcome_unknown again, and a Ctrl+C during a hanging stat still stops the cleanup. Draining the queued signal before the select also restores the behavior, but the forward into the channel is not ordered before the cancellation the copy observed, so the drain can run too early. Either way, add a test that builds its context with interrupt.NotifyContext, sends itself one SIGINT and asserts a stat and an rm on the staging path; the hand-cancelled test cannot cover this.
Nits
- Three decisions still have no test (
internal/fs/drive9_companion.go:577). Removing the bound check leaves the family green, so "an expired bound is reported as a timeout" is unpinned; the same holds for both "the stat was refused and the removal answered not found" decisions (:581-586). The fake can already produce the two latter (TI_FAKE_DRIVE9_STAT_DENIED=ti-tmptogether withTI_FAKE_DRIVE9_CP_STAGED_FAIL=1, or withTI_FAKE_DRIVE9_MV_APPLIED_FAIL=1); a switch that makes the stagingstathang would pin the bound. The fake also keeps branches no test reaches:denied == "1",&& !applied, and themvandrmnot-found branches. - Shape (
:566). The samefs rmis still built and run at two sites with a copied "not found" decision (:566-570,:580-588), and the positionalafterMove boolis still there.drive9StagingLeftoverErrornow takes anopeningstring that has one call site and one value, and that call dropped the old "copying to the staging path for …" wording, so a failed staged copy now opens withreplacing "…" failed (fs cp: …). AndcleanDrive9CopyStagingremoves nothing in the absent case and always returns the error the user sees, so its name describes one of its three outcomes. - Text.
failuerein the comment at:609.README.md:192lists "a token without read on the staging sibling" as a cause offs.copy_staging_unchecked; a token withoutreadbut withdeletegets the file removed and the copy error alone. The PR description is behind in three places: its permission requirement lacks thereadin the destination's directory, it still says "the companion has none" about the overwrite flag, and its list of what the published page needs omitsfs.copy_staging_unchecked.
Recommendation
Request changes. On the first Ctrl+C or SIGTERM the staging cleanup no longer runs, which is the case the round-3 fix was about, and the README, the description and the commit message state the opposite.
interrupt.Signals(checkCtx) returns the command's channel, which already holds the signal that cancelled the copy: the select took the 'further signal' branch immediately, so on the first Ctrl+C the cleanup made no companion call, the staging file stayed, and a rename that had committed was no longer reported as fs.copy_outcome_unknown. The registration is now fresh for the cleanup (SIGINT/SIGTERM), the same way the mount code does it, so only a signal delivered after the cleanup started stops it. Pinned with a test that builds its context with interrupt.NotifyContext, sends itself one SIGINT and requires a stat and a removal on the staging path; the hand-cancelled test could not see this. Verified against the built binary with a partially written staged copy: one SIGINT now runs stat, cp, stat and rm and leaves nothing behind. Also from the review: the removal answers whether the staging file was there, so 'not found' reads as absent rather than as a failed cleanup; the stage is an enum instead of a positional bool and chooses the leftover wording (a failed staged copy opens with 'copying to the staging path for …' again); the cleanup function is named for what it does; the one-fs-rm helper is shared. Tests for the expired bound (now a variable so it can be shortened), and for a refused stat whose removal answers not found before and after the move. The fake gained a hanging stat and lost two branches no test reached. README: fs.copy_staging_unchecked now says it needs a token that can neither read nor delete the staging sibling, and the description carries read in the destination's directory plus the unchecked code in the docs follow-up.
|
This was a real bug and it was mine: signalCh := make(chan os.Signal, 2)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(signalCh)Only a signal delivered after the cleanup started can stop it now. On the built binary, with a staged copy that leaves a partially written sibling and one SIGINT during it: On the previous head the last two lines did not happen. A committed rename interrupted by the same signal reports The test you asked for. The three untested decisions are pinned too:
Shape. The removal now returns whether the staging file was there, so "not found" reads as absent instead of as a failed cleanup, and both branches share one Text.
|
The test sends itself SIGINT with syscall.Kill, which does not exist on windows, and the test file is type-checked for every platform by the vet step. Move it to a !windows file; the behaviour it pins is unix-only by construction.
|
CI caught one thing in Verified locally: |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
The last two commits give the staging cleanup its own SIGINT/SIGTERM registration and pin the fix with a test that fails the copy's context with a real signal. The blocking item is resolved: with exactly one Ctrl+C or SIGTERM the cleanup now runs - during the staged copy it stats the staging path and, when the node was created, removes it; during the move it removes the staging file; a move that had already committed is reported as fs.copy_outcome_unknown again - while a signal that arrives while the cleanup runs still stops it, and with no signal the 30 second bound expires as documented. The same inputs against dab7caf3 still show the cleanup abandoned, and replacing the fresh registration with interrupt.Signals(checkCtx) fails the new test with exactly that symptom. The fifth review's nits are taken: the bound check and both "stat refused, removal answered not found" decisions have tests, the two fs rm sites are one helper, the stage chooses the leftover opening again, and the README is accurate. No correctness or security defect remains on this head, and nothing changed for users without --overwrite. Nothing further is requested; this approval supersedes the changes requested on dab7caf3.
What looks good
- The fix is the smallest correct one: a fresh registration, no change to the cleanup's decisions, and a reproduction that is sensitive to exactly this change.
TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopyexercises the real mechanism (interrupt.NotifyContextplus a real SIGINT) instead of a hand-cancelled context, fails deterministically on the old select, and is safe next to the rest of the package (no test of the package runs in parallel; the whole package is clean under the race detector).removeDrive9Staginganswering "was it there" removes the duplicatedfs rmand its copied "not found" reading, anddrive9CopyStagereads better than the positional bool at both call sites.
Verified on this head
- Build, vet for the host, for Windows and for Linux, the package tests, and the race detector on the whole
fspackage: all pass; CI is green. - Every cleanup branch reports what can have happened on the pinned service: absent, present, refused look, expired bound and signal during the cleanup, before and after the move.
Nits
None that need another commit.
Needs no commit (the description only)
- Three sentences still disagree with the code: the permission requirement lacks
readin the destination's directory; "(no flag is forwarded - the companion has none)" - the companion'sdrive9 fs cphas-f|--force, for object-store URIs only; andfs.copy_staging_uncheckedis listed for "a token without read on the sibling", where a token withdeletegets the file removed and the copy error alone.README.md:192already has the right wording for all three. - The test list does not name the three tests this change adds.
- The sixth commit message says the pinned behaviour "is unix-only by construction"; only the test's
syscall.Killis. The production code compiles for Windows andsignal.Notifydelivers Ctrl+C there as well, so the fix applies there without a test. Worth a sentence in the description; the message itself is not worth a rewrite.
Follow-up material, not for this PR
- Three cleanup decisions have no test: a further signal stopping the cleanup; a look that saw the file followed by a removal that answers "not found" (now read as absent); and the stage-chosen opening of
fs.copy_staging_left_behind.TestDrive9CopyFailureRefusedStatWithGoneStagingsets two fake switches its subtests never read, and the fake'smvnot-found branch is unreachable. - The fresh-registration idiom now sits at three sites (
drive9_companion.go,fuse_mount.go,vault_mount.go), each repeating the signal list thatcmd/ti/main.goregisters; andinterrupt.Signalsdoes not say that code which runs because the first signal cancelled the context must not select on that channel for a further one. One sentence there, or a small helper ininternal/interrupt, would keep the fifth-round defect from coming back. - Carried over: the published
ti-fs-copy-filepage, the copy family's own file, and the "not found" text match on a gateway 404 page.
Recommendation
Approve. The blocking item is fixed and reproduces as fixed; only optional follow-ups remain.
|
Both done, and thank you for the rounds — the signal-channel bug was the kind of thing only a replay catches.
Nothing merged from my side — merging is yours. The branch is at |
…al hazard The approval listed three cleanup decisions without a test and two dead paths in the fake; they are cheap to close now. - TestDrive9CopyFailureSecondSignalStopsTheCleanup: a signal that arrives while the cleanup is running stops it and reports that the staging path was not checked. - TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook: the file is there for the look and gone for the removal, before the move (copy error) and after it (fs.copy_outcome_unknown). - The two leftover tests now assert the opening, so the stage chooses between 'copying to the staging path for …' and 'replacing …'. The fake gained TI_FAKE_DRIVE9_REMOVE_VANISHED for the vanished removal, lost its unreachable mv not-found branch, and the refused-stat test no longer sets two switches its subtests never read. interrupt.Signals now says that the channel already holds the signal that cancelled the context, so code running because of that cancellation must register its own channel instead of selecting on this one - the defect the last review found.
|
The description-only items were already updated before this message, and I have now closed the optional follow-up nits too, in
Still deliberately out of this PR, as you listed them:
The branch is at |
… them - The copy family moves out of drive9_companion.go (2,338 lines) into drive9_copy.go: the route resolver, the --overwrite probe, the server-side replace with its staging cleanup, and the companion argv they share. No behaviour change; drive9_companion.go is 1,710 lines and the copy file 655. - The post-cancel signal registration is interrupt.NotifyStop, used by the cleanup and by the two mount paths instead of three copies of the same channel registration. NotifyStop starts empty - a signal delivered before it registered is not replayed - which is the property the fifth review's defect turned on; a test pins it. - isDrive9NotFound no longer reads a transport-level 'HTTP <code>: <body>' rendering as the API's not-found answer. That body comes from whatever answered the request (a gateway page titled Not Found included), so it says nothing about the path; a failed look now surfaces as unknown rather than 'the file is gone'.
|
Your 'follow-up material' was all in this repo, so instead of carrying it I closed it in
Remaining, and genuinely not this repo: the published Local: |
mornyx
left a comment
There was a problem hiding this comment.
Review summary
This covers the two commits since the approval on 58f3fba2: 26902c4d (tests and one comment) and 10847d62. The copy family's move into drive9_copy.go is a pure move, interrupt.NotifyStop is equivalent to the three registrations it replaced, and the stricter isDrive9NotFound only fails more conservatively. Everything the earlier approval relied on still holds on this head, checked with real signals on the built binary, and the predicate change closes a real hole in the --overwrite guard. Nothing further is needed for this PR; this approval stands on 10847d62.
Verified on this head
- The move is pure: of the 116 top-level declarations in the old
drive9_companion.go, 114 are identical across the two files, the two that differ are the intended edits (drive9CopyFailure,isDrive9NotFound), one var was added, none is missing, and no declaration moved that has a caller outside the copy family. NotifyStopregisters the same two signals on a channel of the same size and releases it at the same points. ANotifyStopthat hands every caller one shared channel now failsTestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy.- One Ctrl+C or SIGTERM during the staged copy, during the move, or during a committed move; a second signal during the cleanup; the expired bound: the same results as at the approved head.
- The stricter
isDrive9NotFound, compared on built binaries of26902c4dand this head: the service's own not-found answers are still recognised in every flow, and a transport-levelHTTP <code>: <body>page is no longer read as "absent". Every caller changes in the conservative direction. - Build, vet for the host, Windows and Linux, the tests of all 46 packages, the race detector with shuffle, and the signal tests over repeated runs: all pass. CI is green, including its
make e2e. On this machine three mount e2e tests cannot complete (no FUSE device) and fail identically onmain.
What looks good
- The split reverses the growth this PR had caused in
drive9_companion.go(2,338 to 1,710 lines) and gives the copy family one 655-line file with an accurate header. - The predicate change closes a real hole. A plain upload whose destination probe is answered by a transport page used to run and replace an existing destination without
--overwrite(reproduced on26902c4d); it now fails closed with the destination intact. After a refused move it turns two false reports into truthful ones: a leftover that is really there is named asfs.copy_staging_left_behindinstead offs.copy_outcome_unknown, and a removal is attempted instead of skipped. - The follow-ups from the earlier approval were closed in the PR instead of deferred, and the new tests fail under the mutations they guard.
Nits
None that need another commit.
Needs no commit (the description only)
- The predicate change is wider than the commit message and the description say. Besides the cleanup's look it changes the cleanup's removal, the destination probe of a copy without
--overwrite,ti fs-vault delete-secretanddelete-grant(a transport page on the retry after a transient failure is now an error instead of"status": "deleted"), andti fs-vault replace-secret(it now stops at a failedvault rm). All of that is the right direction, and the README promises nothing about it, but the description should name it in one sentence. - The test list lacks the four tests added by the last two commits, and the failure-handling list states one bullet twice.
- The ninth commit message says "a test pins it" for
NotifyStop.TestNotifyStopStartsEmptycannot fail for that property; the pin isTestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopyininternal/fs. Worth a sentence in the description; the message itself is not worth a rewrite.
Before release, not for this PR
- The stricter match assumes that the service's own 404 reaches the companion as JSON. That holds for the pinned server. If the deployed endpoint sat behind something that rewrote 404 bodies, every copy onto a new path would fail at its probe. The live copy steps, which have not been run against the deployed service, settle it in one run: a copy onto a new path without
--overwrite, then one onto an existing path with it. - Carried over: the published
ti-fs-copy-filepage.
Recommendation
Approve. The refactor preserved everything the earlier approval relied on, the stricter predicate is correct and only fails more conservatively, and what remains is description text and a release-time check.
|
Description-only items, all taken (no commit, per your note):
What stays outside the PR, as you listed it:
Nothing else from the nits is open, and I have not merged anything. |
What
The three follow-ups left out of #99, in one PR.
1.
--overwritereplaces a server-side copyA remote to remote copy cannot replace anything at the service:
POST <path>?copyinserts a new node, the unique path index rejects the duplicate, and that surfaces as500 {"error":"backend unavailable"}. #99 therefore refused the shape.ti fs copy-file --overwriteshould mean what it says, so ti now performs the replacement itself:dir/<base(source)>; a symlink only on a local destination, because the service treats a remote link as a file whose payload is the target path),<destination>.ti-tmp-<8 hex>path,fs mv.The service's rename replaces the target in one datastore transaction (
RenameFileReplacingTarget), so a reader sees either the old file or the complete new one, and a failed copy never touches the destination. The probe and the replace share one destination resolver, so they cannot disagree about the path a copy writes.Failure handling, all of it user-visible:
fs stat, retried) instead of inferring it from onefs rmanswer, because the service authorizesDELETEbefore it looks the path up: a token without delete answers "access denied" for a file that was never created,fs.copy_staging_left_behindcarries the copy error as its cause,fs.copy_staging_left_behind, naming the staging path and theti fs delete-file --paththat removes it (that command needs delete on the path, which is exactly what was refused),fs.copy_outcome_unknownnames both paths, points atti fs describe-filefor each and says re-running with--overwriteis safe,fs.copy_staging_uncheckedand says which.ti-tmp-entry to look for, instead of claiming the file exists,fs rm: not foundline,--overwriteon a shape that resolves to the source is refused before any write,fs.remote_copy_target_is_directory.Uploads and downloads keep their single native write: with
--overwriteti skips its own probe and the companion's plain write replaces the destination (no flag is forwarded; the companion'sdrive9 fs cphas only-f|--force, honored for object-store URIs).2. Scheme-spelled and drive9-spelled local paths are refused
The companion resolves a location scheme itself and reads a
:prefix as a drive9 path, while ti probes a local destination as a literal filesystem path.--to-local file:///path(or--to-local :/path) therefore passed the probe and still wrote somewhere else.--from-local/--to-localnow reject both spellings withfs.local_path_scheme_unsupported: every scheme the companion knows (s3://included), and a leading:. A single-letter scheme is a Windows drive letter and an opaque URL (a:b) is a legal file name, so neither is caught by mistake.3. Docs match the code
The
--overwritehelp and the README paragraph describe what each direction does, the staging move, the real permission requirement (read on source and destination, and read, write and delete in the destination's directory), the listing visibility and.ti-tmp-suffix, the unknown-outcome case, the two new refusals and the symlink scoping.In-repo follow-ups are done in this PR (
10847d6): the copy family has its own file, and the post-cancel signal registration is oneinterrupt.NotifyStophelper used by the cleanup and both mount paths.TestNotifyStopStartsEmptypins that a fresh registration does not replay an earlier signal; the property the cleanup needs — the signal that cancelled the copy does not abandon it — is pinned byTestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopyininternal/fs.isDrive9NotFoundno longer reads a transport-levelHTTP <code>: <body>page as the API's not-found answer. That is wider than the cleanup: the destination probe of a copy without--overwritenow fails closed instead of letting a transport page stand in for "absent" (so it can no longer overwrite a destination that is there), the cleanup's removal is attempted instead of skipped, and two vault flows change in the same conservative direction —ti fs-vault delete-secret/delete-grantreport an error instead of"status": "deleted"when the retry after a transient failure lands on a transport page, andti fs-vault replace-secretstops at a failedvault rm.Follow-up (different repo):
docs/pingcap-docs/docsis a submodule pinned ata8e00c35ofpingcap/docs;ai/ti/reference/commands/fs/ti-fs-copy-file.mdstill says--overwrite: "Replace an existing destination file." It needs the direction-specific text, the staged rename,fs.remote_copy_target_is_directory,fs.copy_staging_left_behindwith itsdelete-fileremedy,fs.copy_outcome_unknownwith itsdescribe-fileadvice,fs.copy_staging_uncheckedwith its "look for a.ti-tmp-entry" wording, andfs.local_path_scheme_unsupported. A pointer bump needs a commit inpingcap/docsfirst, so it is its own change.Tests
go build ./...,go vet ./...,go test ./... -count=1pass.TestDrive9CopyServerSideOverwriteStagesAndMoves: existing file destination and existing inner path under a directory destination →cp <source> <target>.ti-tmp-*thenmv <staged> <target>, result reports the destination the caller named.TestDrive9CopyServerSideOverwriteWithoutExistingTargetCopiesOnce: no staging when nothing is there.TestDrive9CopyServerSideOverwriteRejectsDirectoryTarget:fs.remote_copy_target_is_directory, no write.TestDrive9CopyServerSideOverwriteRefusesSelfCopy: both spellings of a collision, no write.TestDrive9CopyServerSideOverwriteCleansUpAfterFailedMove: staging removed, the move error surfaces.TestDrive9CopyServerSideOverwriteNamesTheStagingPathWhenCleanupFails:fs.copy_staging_left_behindnames the path, thedelete-filecommand and its delete requirement.TestDrive9CopyServerSideOverwriteAppliedMoveLostAnswer: the fake applies the rename and then fails, so the staging file is gone →fs.copy_outcome_unknownnaming both paths and never a delete.TestDrive9CopyServerSideOverwriteCleansUpAfterFailedStagedCopy: after a failed staged copy there is nomv, the staging file is gone from the fake's path set, and only the destination remains;...NamesStagingAfterFailedStagedCopypins the refused-cleanup message.TestDrive9CopyServerSideOverwriteReportsUncheckedStaging: a token that can read the destination and not the staging sibling, with a refused removal →fs.copy_staging_unchecked, saying ti could not determine whether the file exists.TestDrive9CopyFailureCleansUpOnCancelledContext: a cancelled copy still stats and removes the staging file, and the original error comes back.TestDrive9CopyFailureCleansUpAfterTheSignalThatFailedTheCopy(!windows, because it sends itself SIGINT withsyscall.Kill): the signal that cancelled the copy does not stop the cleanup; replacing the fresh registration withinterrupt.Signals(checkCtx)fails it. Only the test is unix-only — the production code compiles and behaves the same on Windows, wheresignal.Notifyalso delivers Ctrl+C.TestDrive9CopyFailureReportsExpiredCleanupBound: a hanging stagingstatpast the (shortened) bound reportsfs.copy_staging_uncheckedwith the timeout, not a refused removal.TestDrive9CopyFailureRefusedStatWithGoneStaging: a refusedstatwhose removal answers "not found" reads as absent — the copy error before the move,fs.copy_outcome_unknownafter it.TestDrive9CopyFailureRemovalAnswersNotFoundAfterTheLook: the staging file is there for the look and gone for the removal — the copy error before the move,fs.copy_outcome_unknownafter it.TestDrive9CopyFailureSecondSignalStopsTheCleanup: a signal that arrives while the cleanup is running stops it and reports that the staging path was not checked.TestNotifyStopStartsEmpty: a freshinterrupt.NotifyStopregistration does not replay a signal delivered before it.TestIsDrive9NotFoundIgnoresTransportStatusBodies:HTTP <code>: <body>from whatever answered the request is not the API's not-found answer.TestDrive9CopyServerSideOverwriteNoLeftoverWhenNothingWasCreated: a token without delete and a staged copy that created nothing must report the copy error alone.TestDrive9CopyUploadAndDownloadOverwriteStaySingleCall: onecp, nomv.TestDrive9CopyRejectsSchemeSpelledLocalPaths:file://,file:, and:spellings.TestDrive9CopyArgsForTargetRejectsNonRemoteRoutes: the retarget guard.TestDrive9CopyUploadRejectionStillOffersOverwritenow also covers an upload whose local absolute path spells the remote destination (it must keep the flag advice, not claim "is the source path").Live e2e: the remote-pair refusal is asserted, then an existing remote path is copied onto both without and with
--overwrite(exit 2 with the advice, then exit 0 with the source bytes), androotPathis listed afterwards to prove no.ti-tmp-entry survives.I also replayed the live copy steps against the built binary with a stand-in companion (all three directions,
fs mkdir/fs cat/fs mv, the service's duplicate-path rejection): 24/24 checks pass, including the staged.ti-tmp-*copy, the move onto the destination, the replaced bytes, no staging leftover, the scheme refusal, and the upload/drive9 spelling separation.