v1.27.0-a #10

Closed
jonathanface wants to merge 473 commits from v1.27.0-a into master
Showing only changes of commit 9560c3efaf - Show all commits

View File

@ -3,6 +3,7 @@ package config
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/mitchellh/go-homedir"
"io" "io"
"io/fs" "io/fs"
"os" "os"
@ -14,6 +15,11 @@ import (
) )
func StorageFromFile(path string, def *storiface.StorageConfig) (*storiface.StorageConfig, error) { func StorageFromFile(path string, def *storiface.StorageConfig) (*storiface.StorageConfig, error) {
path, err := homedir.Expand(path)
if err != nil {
return nil, xerrors.Errorf("expanding storage config path: %w", err)
}
file, err := os.Open(path) file, err := os.Open(path)
switch { switch {
case os.IsNotExist(err): case os.IsNotExist(err):
@ -40,6 +46,11 @@ func StorageFromReader(reader io.Reader) (*storiface.StorageConfig, error) {
} }
func WriteStorageFile(filePath string, config storiface.StorageConfig) error { func WriteStorageFile(filePath string, config storiface.StorageConfig) error {
filePath, err := homedir.Expand(filePath)
if err != nil {
return xerrors.Errorf("expanding storage config path: %w", err)
}
b, err := json.MarshalIndent(config, "", " ") b, err := json.MarshalIndent(config, "", " ")
if err != nil { if err != nil {
return xerrors.Errorf("marshaling storage config: %w", err) return xerrors.Errorf("marshaling storage config: %w", err)