mirror of
https://github.com/restic/restic.git
synced 2026-11-23 13:52:39 +00:00
restic init generated and uploaded the key file first and only saved the config afterwards. If two clients ran init against the same empty repository location at nearly the same time, the backend could end up with two key files but only one config file, since backends that reject overwrites let only one of the two config writes succeed. The losing client's key file stayed in the repository without ever belonging to a valid config, so clients picking that key later would fail with a "config or key ... is damaged" error instead of a clear diagnostic. Reorder Repository.init so the config is saved before the key file is uploaded. To make that possible, AddKey no longer generates a random master key internally; callers now supply the master key to encrypt and store. The two other callers of AddKey (key add, key passwd) already had an existing key available and pass that through unchanged.