Write encrypt and decrypt output only once they succeed (closes #143)
check / check (push) Canceled after 0s

`secret encrypt` and `secret decrypt` emptied the file named by
`--output` before reading any input, so a failure left it empty, and a
file given as both `--input` and `--output` was emptied before it was
read. They now write into a temporary file of mode 0600 next to it and
rename that over it only on success, using the new
`secret.WriteFileAtomicFunc`, which `secret.WriteFileAtomic` now calls.
A device or pipe given as `--output`, such as `/dev/null`, is written to
directly instead of being replaced by a file.

Judgement call: the device and pipe case goes beyond the plan.
Judgement call: a symbolic link given as `--output` is replaced, not followed.

Model: opus-5-5
This commit is contained in:
2026-10-14 17:56:51 +00:00
parent fd6c5df1a8
commit 90bfbec5cb
5 changed files with 215 additions and 47 deletions
+7
View File
@@ -274,6 +274,13 @@ generates a new Age key.
Decrypts data using an Age key stored as a secret.
Both write the result to a new file next to `--output` and rename it over
`--output` only once they have succeeded, so a failed command leaves an existing
`--output` as it was and creates none, and `--input` and `--output` can be the
same file. The file has mode 0600, whatever mode the file it replaced had, and
when `--output` is a symbolic link to a file, the link itself is replaced. A
device or a pipe, such as `/dev/null`, is written to directly.
## Storage Architecture
### Directory Structure