Skip to content

fix: use sudoRunWithFallback for atomic-swap rollback in Upload#3

Merged
webcane merged 1 commit into
masterfrom
fix/sudo-rollback-atomic-swap
May 19, 2026
Merged

fix: use sudoRunWithFallback for atomic-swap rollback in Upload#3
webcane merged 1 commit into
masterfrom
fix/sudo-rollback-atomic-swap

Conversation

@webcane
Copy link
Copy Markdown
Owner

@webcane webcane commented May 19, 2026

What changed

In internal/filetransfer/upload.go, the three-step atomic swap used sudoRunWithFallback for the two forward mv operations but fell back to plain sshExec for the rollback mv. On a typical VPS where /opt/… is root-owned, sshExec fails silently — the error was discarded with _ =, leaving remoteBase absent on disk while remoteBase-old-<timestamp> still exists. The next deploy then incorrectly takes the first-deploy code path.

Fix

  • Replace _ = sshExec(…) with rollbackErr := sudoRunWithFallback(…) in the rollback path. The closure already holds cached credentials from the preceding forward moves, so no second interactive prompt is issued.
  • Return a distinct error message depending on whether the rollback itself succeeded or failed, so operators get an actionable sudo mv recovery command when both operations fail.
  • Remove the now-incorrect "If rollback failed…" hint from the success-rollback error message.

Testing

go build ./internal/filetransfer/... passes. The change is a targeted substitution within existing error-handling logic with no new code paths to cover separately.

Plain sshExec silently fails on sudo-protected /opt/… paths, leaving
remoteBase absent on disk after a failed step-2 mv. The next deploy
would then incorrectly take the first-deploy path.

Switch the rollback mv to the sudoRunWithFallback closure (which already
holds the cached credentials from the preceding forward moves). Also
surface a distinct error message depending on whether the rollback
itself succeeded or failed, so operators get an actionable manual
recovery command when both operations fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@webcane webcane merged commit f0187c3 into master May 19, 2026
2 checks passed
@webcane webcane deleted the fix/sudo-rollback-atomic-swap branch May 19, 2026 07:45
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.

1 participant