From 40a7ccd60bccae13a1284324b9da693617d709ea Mon Sep 17 00:00:00 2001 From: mworzala Date: Sat, 16 Sep 2023 08:37:35 -0400 Subject: [PATCH] fix: keychain not created when accounts file is missing (fixes #9) --- internal/pkg/account/account.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/pkg/account/account.go b/internal/pkg/account/account.go index 0827937..b9204a6 100644 --- a/internal/pkg/account/account.go +++ b/internal/pkg/account/account.go @@ -69,12 +69,15 @@ type fileManager struct { func NewManager(dataDir string, config *config.Config) (Manager, error) { + keychain := NewKeychain(dataDir, config.UseSystemKeyring) + // Read the accounts file accountsFile := path.Join(dataDir, accountsFileName) if _, err := os.Stat(accountsFile); errors.Is(err, fs.ErrNotExist) { return &fileManager{ Path: accountsFile, AccountData: make(map[string]*Account), + Keychain: keychain, }, nil } f, err := os.Open(accountsFile) @@ -84,13 +87,15 @@ func NewManager(dataDir string, config *config.Config) (Manager, error) { defer f.Close() // Construct the manager - manager := fileManager{Path: accountsFile, AccountData: make(map[string]*Account)} + manager := fileManager{ + Path: accountsFile, + AccountData: make(map[string]*Account), + Keychain: keychain, + } if err := json.NewDecoder(f).Decode(&manager); err != nil { return nil, fmt.Errorf("failed to read %s: %w", accountsFileName, err) } - manager.Keychain = NewKeychain(dataDir, config.UseSystemKeyring) - return &manager, nil }