Skip to content

ops-get: replace the destination by rename, never write into it - #102

Merged
margani merged 1 commit into
mainfrom
fix/98-ops-get-rename
Nov 2, 2026
Merged

margani merged 1 commit into
mainfrom
fix/98-ops-get-rename

Conversation

@margani

@margani margani commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Closes #98.

What changed

  • ops-get writes the verified script to a new mktemp file in the destination's directory, sets mode 755, and renames it over the destination. If any step fails (for example, renaming over another user's file in a sticky directory), it removes the temp file and stops with a message. A destination that is a directory is refused.
  • ops-get.ps1 does the same with a GUID-named temp file and Move-Item -Force.
  • README and server/README quick starts fetch to ./server.sh instead of /tmp/server.sh.

Why

cp onto an existing destination rewrote that file in place. The file kept its owner, and a 0666 file became 0777 after chmod +x, so the file later run with sudo was not bound to the verified bytes.

Verification

  • tests/ops-get_test.sh: new case pre-creates a 0666 destination and asserts a new inode, mode 755, the right content and no leftover temp file. On the old code: FAIL: the existing destination was written in place.
  • tests/ops-get_test.ps1 (pwsh 7 on Linux): a hard link to the pre-existing file must keep the old content. On the old code: FAIL: the existing destination was written in place; new code: PASS.
  • ./run-tests: all 10 passed, 3 skipped.
  • ops-get.ps1 stays ASCII-only (checked).

Not verified

  • Windows PowerShell 5.1 and Windows pwsh run in CI on this PR.
  • A real two-user host. The sticky-directory refusal follows from rename(2) semantics and was not run with two uids.
  • ops-get's hash changes. README's pinned hash is updated after the next release, as usual.

cp into an existing destination kept that file's owner and write bits, so a
file another local user had created stayed theirs to change before it was run.
Both ops-get and ops-get.ps1 now write a new file beside the destination and
rename it over; if that is not allowed they stop. The quick starts fetch into
the current directory instead of /tmp.

Closes #98
@margani
margani merged commit 141f11c into main Nov 2, 2026
4 checks passed
@margani
margani deleted the fix/98-ops-get-rename branch November 2, 2026 19:49
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.

ops-get: replace the destination by rename instead of writing into an existing file

1 participant