From c91e650d53bbc9781380c269d28ba1a2841b3b9d Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Mon, 22 Jul 2019 22:47:20 +0200 Subject: [PATCH] feat: create the wallets directory --- CHANGELOG.md | 1 + gpm/config.go | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdeaddd..cf3c0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) - Print the expiration time of TOTP code - Export a wallet in json - Import entries from a json file +- Create the wallets directory ## Changed diff --git a/gpm/config.go b/gpm/config.go index d555687..b075f9d 100644 --- a/gpm/config.go +++ b/gpm/config.go @@ -58,20 +58,29 @@ func (c *Config) Init() error { // Load the configuration from a file func (c *Config) Load(path string) error { - _, err := os.Stat(path) + err := c.Init() if err != nil { - err = c.Init() + return err + } + + if path != "" { + _, err = os.Stat(path) + if err != nil { + + } + + data, err := ioutil.ReadFile(path) + if err != nil { + return err + } + + err = json.Unmarshal(data, &c) if err != nil { return err } } - data, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - err = json.Unmarshal(data, &c) + err = os.MkdirAll(c.WalletDir, 0700) if err != nil { return err }