Make the StoreKeys function automatically set up the file if it's not already there

This commit is contained in:
idk
2022-08-03 16:46:30 -04:00
parent b97558c06a
commit 910de44ac8

View File

@ -86,6 +86,16 @@ func StoreKeysIncompat(k I2PKeys, w io.Writer) (err error) {
}
func StoreKeys(k I2PKeys, r string) error {
if _, err := os.Stat(r); err != nil {
if os.IsNotExist(err) {
fi, err := os.Create(r)
if err != nil {
return err
}
defer fi.Close()
return StoreKeysIncompat(k, fi)
}
}
fi, err := os.Open(r)
if err != nil {
return err