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

Function LoadStore

internal/cli/credentials.go:108–126  ·  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

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

Callers 15

loginCmdFunction · 0.92
logoutCmdFunction · 0.92
whoamiCmdFunction · 0.92
authSignupCmdFunction · 0.92
padInitCmdFunction · 0.92
printInitStatusFunction · 0.92
readSavedCredsFunction · 0.92
TestHeadlessSetupSuccessFunction · 0.92

Calls 5

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