create .ollama directory if it doesnt exist

This commit is contained in:
Jeffrey Morgan 2023-08-11 15:35:55 -07:00
parent 148f0225c0
commit 1556162c90
2 changed files with 8 additions and 8 deletions

View file

@ -9,12 +9,12 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -585,7 +585,12 @@ func initializeKeypair() error {
return err return err
} }
err = ioutil.WriteFile(privKeyPath, pem.EncodeToMemory(privKeyBytes), 0600) err = os.MkdirAll(path.Dir(privKeyPath), 0o700)
if err != nil {
return fmt.Errorf("could not create directory %w", err)
}
err = os.WriteFile(privKeyPath, pem.EncodeToMemory(privKeyBytes), 0600)
if err != nil { if err != nil {
return err return err
} }
@ -597,7 +602,7 @@ func initializeKeypair() error {
pubKeyData := ssh.MarshalAuthorizedKey(sshPrivateKey.PublicKey()) pubKeyData := ssh.MarshalAuthorizedKey(sshPrivateKey.PublicKey())
err = ioutil.WriteFile(pubKeyPath, pubKeyData, 0644) err = os.WriteFile(pubKeyPath, pubKeyData, 0644)
if err != nil { if err != nil {
return err return err
} }

View file

@ -63,11 +63,6 @@ func getAuthToken(redirData AuthRedirect, regOpts *RegistryOptions) (string, err
keyPath := path.Join(home, ".ollama", "id_ed25519") keyPath := path.Join(home, ".ollama", "id_ed25519")
err = os.MkdirAll(path.Dir(keyPath), 0700)
if err != nil {
return "", fmt.Errorf("could not create .ollama directory %w", err)
}
rawKey, err := os.ReadFile(keyPath) rawKey, err := os.ReadFile(keyPath)
if err != nil { if err != nil {
log.Printf("Failed to load private key: %v", err) log.Printf("Failed to load private key: %v", err)