Skip to content

Commit 96b87f5

Browse files
authored
Make Config Directory Creation Explicit (#148)
* fix: rename init function to InitConfigDir for clarity (#147) * fix: ensure home directory is created if it doesn't exist during keystore import
1 parent 2943ce8 commit 96b87f5

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pkg/account/import.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ func ImportKeyStore(keyPath, name, passphrase string) (string, error) {
126126
if hasAddress {
127127
return "", fmt.Errorf("address %s already exists in keystore", key.Address.String())
128128
}
129+
// create home dir if it doesn't exist
130+
store.InitConfigDir()
129131
uDir, _ := homedir.Dir()
130132
newPath := filepath.Join(uDir, common.DefaultConfigDirName, common.DefaultConfigAccountAliasesDirName, name, filepath.Base(keyPath))
131133
err = writeToFile(newPath, string(keyJSON))

pkg/store/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15-
func init() {
15+
func InitConfigDir() {
1616
uDir, _ := homedir.Dir()
1717
tronCTLDir := path.Join(uDir, c.DefaultConfigDirName, c.DefaultConfigAccountAliasesDirName)
1818
if _, err := os.Stat(tronCTLDir); os.IsNotExist(err) {

0 commit comments

Comments
 (0)