Write encrypt and decrypt output only once they succeed (closes #143)
check / check (push) Waiting to run

`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 file 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.
Judgement call: a link to a file that does not exist yet is replaced.

Model: opus-5-5
This commit is contained in:
2026-10-14 18:28:40 +00:00
parent fd6c5df1a8
commit accfd5878f
7 changed files with 371 additions and 47 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 and the link kept. A device or a pipe, such as `/dev/null`, is written
to directly.
## Storage Architecture
### Directory Structure