Fix forgetoption
and configoption
when saving the config file
#402
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's a number of open issues about crashes coming from
forgetoption
andconfigoption
:This happens when
autorestic
generates a secret key for a backend that doesn't already have one. Under the hoodautorestic
will generate the key and then write the config to disk. During this write operation, invalid config options were introduced which leadsautorestic
to crash on following runs.This bug happens because of a quirk in
viper
(the config lib used byautorestic
). Whenviper
reads a config to astruct
it does so using themapstructure
tags but when it write the config from astruct
it doesn't use those. It instead just passes it to https://pkg.go.dev/gopkg.in/yaml.v2 which uses theyaml
tags.The fix here is a bit of a hack. I simply duplicated all the
mapstructure
tags into newyaml
tags with the exact same values. Themapstructure
tags are used for reading and theyaml
tags are used for writing. This is obviously ugly but it does fix the issue.I know that @cupcakearmy had some plans of removing the config writing feature from
autorestic
. While I think that this is a good idea in the long run, I'm hoping that this fix here is a good way to fix the bug without introducing a potentially breaking change for users.Example result
Here's an example of the resulting config from this PR:
example-config.yml
:Generating the
key
:Updated config:
Notice that
autorestic
has written akey
for theexample
backend but the config is not polluted with noisy fields. The only issue with this is that the fields are re-ordered. This is not great but I believe that it's tolerable.