diff options
| author | Noah Kleiner <[email protected]> | 2021-03-09 12:42:33 +0100 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-03-09 08:50:42 -0500 |
| commit | 3da7fe7cee32404927b400309ed373a50b9ea8a4 (patch) | |
| tree | e341456111b48d8f1ffc9c81679cdcf7189ad24a /tofu | |
| parent | Remove StatusSensitiveInput (diff) | |
| download | go-gemini-3da7fe7cee32404927b400309ed373a50b9ea8a4.tar.xz go-gemini-3da7fe7cee32404927b400309ed373a50b9ea8a4.zip | |
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.
Diffstat (limited to 'tofu')
| -rw-r--r-- | tofu/tofu.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tofu/tofu.go b/tofu/tofu.go index 6a7a15e..e2fcebb 100644 --- a/tofu/tofu.go +++ b/tofu/tofu.go @@ -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 |