Skip to content

Commit

Permalink
fix: keychain not created when accounts file is missing (fixes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Sep 16, 2023
1 parent 8cfb004 commit 40a7ccd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/pkg/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 40a7ccd

Please sign in to comment.