1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-05-06 08:46:15 +02:00

tofu: Create path if not exists

This commit is a follow-up to 56774408 which does not take into account
the case that the parent directory of the known_hosts file does not already exist.
This commit is contained in:
Noah Kleiner 2021-03-09 12:42:33 +01:00 committed by Adnan Maolood
parent dea7600f29
commit 3da7fe7cee

View File

@ -10,6 +10,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strings"
"sync"
@ -82,6 +83,10 @@ func (k *KnownHosts) WriteTo(w io.Writer) (int64, error) {
// Load loads the known hosts entries from the provided path.
func (k *KnownHosts) Load(path string) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
return err
}
f, err := os.OpenFile(path, os.O_CREATE|os.O_RDONLY, 0644)
if err != nil {
return err