MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / LoadStore

Function LoadStore

internal/cli/credentials.go:106–124  ·  view source on GitHub ↗

LoadStore reads the credentials file and returns a usable CredentialStore. Returns an empty (but non-nil) store if the file doesn't exist — that's not an error, just "nothing logged in anywhere." Migrates v1 single-blob format to v2 in memory; v1 files stay v1 on disk until the first Save (which alw

()

Source from the content-addressed store, hash-verified

104// never sees a save half-written: Save writes in place, as os.WriteFile
105// did, under the exclusive side of the same lock.
106func LoadStore() (*CredentialStore, error) {
107 var store *CredentialStore
108 err := withCredentialsLock(false, func(path string, locked bool) error {
109 var err error
110 if locked {
111 store, err = loadStoreLocked(path)
112 } else {
113 store, err = loadStoreUnlocked(path)
114 }
115 return err
116 })
117 // A read is only a read: an empty file it could not tell from a save in
118 // progress is answered as no credentials, as before (BUG-3828). The worst
119 // case is a spurious "not logged in"; only UpdateStore must not act on it.
120 if errors.Is(err, errNoCredentialsDir) || errors.Is(err, errCredentialsEmptyUnlocked) {
121 return newEmptyStore(), nil
122 }
123 return store, err
124}
125
126// loadStoreLocked is LoadStore for a caller that holds the credentials lock.
127//

Calls 5

withCredentialsLockFunction · 0.85
loadStoreLockedFunction · 0.85
loadStoreUnlockedFunction · 0.85
newEmptyStoreFunction · 0.85
IsMethod · 0.45