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, or
next to the path it is a symbolic link to, and rename that over it only
on success, using the new `secret.WriteFileAtomicFunc`, which
`secret.WriteFileAtomic` now calls. Ctrl-C or SIGTERM removes the
temporary file. A device or pipe given as `--output`, such as
`/dev/null`, is written to directly.

Judgement call: the device and pipe case goes beyond the plan.

Model: opus-5-5
This commit is contained in:
2026-10-14 19:06:37 +00:00
parent 5371382cb4
commit e08c29438a
7 changed files with 449 additions and 45 deletions
+8
View File
@@ -274,6 +274,14 @@ 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 or interrupted 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. When `--output` is a symbolic link, the file it points to is
replaced, or created if it does not exist yet, and the link kept. A device or a
pipe, such as `/dev/null`, is written to directly.
## Storage Architecture
### Directory Structure