id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
160,000
keybase/client
go/teams/ftl.go
computeFreshLoad
func (s *shoppingList) computeFreshLoad(m libkb.MetaContext, arg fastLoadArg) { s.needMerkleRefresh = true s.applications = append([]keybase1.TeamApplication{}, arg.Applications...) s.downPointers = append([]keybase1.Seqno{}, arg.downPointersNeeded...) s.generations = append([]keybase1.PerTeamKeyGeneration{}, arg.KeyGenerationsNeeded...) }
go
func (s *shoppingList) computeFreshLoad(m libkb.MetaContext, arg fastLoadArg) { s.needMerkleRefresh = true s.applications = append([]keybase1.TeamApplication{}, arg.Applications...) s.downPointers = append([]keybase1.Seqno{}, arg.downPointersNeeded...) s.generations = append([]keybase1.PerTeamKeyGeneration{}, arg.KeyGenerationsNeeded...) }
[ "func", "(", "s", "*", "shoppingList", ")", "computeFreshLoad", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ")", "{", "s", ".", "needMerkleRefresh", "=", "true", "\n", "s", ".", "applications", "=", "append", "(", "[", "]", "keybase1", ".", "TeamApplication", "{", "}", ",", "arg", ".", "Applications", "...", ")", "\n", "s", ".", "downPointers", "=", "append", "(", "[", "]", "keybase1", ".", "Seqno", "{", "}", ",", "arg", ".", "downPointersNeeded", "...", ")", "\n", "s", ".", "generations", "=", "append", "(", "[", "]", "keybase1", ".", "PerTeamKeyGeneration", "{", "}", ",", "arg", ".", "KeyGenerationsNeeded", "...", ")", "\n", "}" ]
// computeFreshLoad computes a shopping list from a fresh load of the state.
[ "computeFreshLoad", "computes", "a", "shopping", "list", "from", "a", "fresh", "load", "of", "the", "state", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L594-L599
160,001
keybase/client
go/teams/ftl.go
applicationsToString
func applicationsToString(applications []keybase1.TeamApplication) string { var tmp []string for _, k := range applications { tmp = append(tmp, fmt.Sprintf("%d", int(k))) } return strings.Join(tmp, ",") }
go
func applicationsToString(applications []keybase1.TeamApplication) string { var tmp []string for _, k := range applications { tmp = append(tmp, fmt.Sprintf("%d", int(k))) } return strings.Join(tmp, ",") }
[ "func", "applicationsToString", "(", "applications", "[", "]", "keybase1", ".", "TeamApplication", ")", "string", "{", "var", "tmp", "[", "]", "string", "\n", "for", "_", ",", "k", ":=", "range", "applications", "{", "tmp", "=", "append", "(", "tmp", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int", "(", "k", ")", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "tmp", ",", "\"", "\"", ")", "\n", "}" ]
// applicationsToString converts the list of applications to a comma-separated string.
[ "applicationsToString", "converts", "the", "list", "of", "applications", "to", "a", "comma", "-", "separated", "string", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L602-L608
160,002
keybase/client
go/teams/ftl.go
generationsToString
func generationsToString(generations []keybase1.PerTeamKeyGeneration) string { var tmp []string for _, k := range generations { tmp = append(tmp, fmt.Sprintf("%d", int(k))) } return strings.Join(tmp, ",") }
go
func generationsToString(generations []keybase1.PerTeamKeyGeneration) string { var tmp []string for _, k := range generations { tmp = append(tmp, fmt.Sprintf("%d", int(k))) } return strings.Join(tmp, ",") }
[ "func", "generationsToString", "(", "generations", "[", "]", "keybase1", ".", "PerTeamKeyGeneration", ")", "string", "{", "var", "tmp", "[", "]", "string", "\n", "for", "_", ",", "k", ":=", "range", "generations", "{", "tmp", "=", "append", "(", "tmp", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int", "(", "k", ")", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "tmp", ",", "\"", "\"", ")", "\n", "}" ]
// generationsToString converts the list of generations to a comma-separated string.
[ "generationsToString", "converts", "the", "list", "of", "generations", "to", "a", "comma", "-", "separated", "string", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L611-L617
160,003
keybase/client
go/teams/ftl.go
makeHTTPRequest
func (f *FastTeamChainLoader) makeHTTPRequest(m libkb.MetaContext, args libkb.HTTPArgs, isPublic bool) (t rawTeam, err error) { apiArg := libkb.NewAPIArg("team/get") apiArg.Args = args if isPublic { apiArg.SessionType = libkb.APISessionTypeOPTIONAL } else { apiArg.SessionType = libkb.APISessionTypeREQUIRED } err = m.G().API.GetDecode(m, apiArg, &t) if err != nil { return t, err } return t, nil }
go
func (f *FastTeamChainLoader) makeHTTPRequest(m libkb.MetaContext, args libkb.HTTPArgs, isPublic bool) (t rawTeam, err error) { apiArg := libkb.NewAPIArg("team/get") apiArg.Args = args if isPublic { apiArg.SessionType = libkb.APISessionTypeOPTIONAL } else { apiArg.SessionType = libkb.APISessionTypeREQUIRED } err = m.G().API.GetDecode(m, apiArg, &t) if err != nil { return t, err } return t, nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "makeHTTPRequest", "(", "m", "libkb", ".", "MetaContext", ",", "args", "libkb", ".", "HTTPArgs", ",", "isPublic", "bool", ")", "(", "t", "rawTeam", ",", "err", "error", ")", "{", "apiArg", ":=", "libkb", ".", "NewAPIArg", "(", "\"", "\"", ")", "\n", "apiArg", ".", "Args", "=", "args", "\n", "if", "isPublic", "{", "apiArg", ".", "SessionType", "=", "libkb", ".", "APISessionTypeOPTIONAL", "\n", "}", "else", "{", "apiArg", ".", "SessionType", "=", "libkb", ".", "APISessionTypeREQUIRED", "\n", "}", "\n", "err", "=", "m", ".", "G", "(", ")", ".", "API", ".", "GetDecode", "(", "m", ",", "apiArg", ",", "&", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "t", ",", "err", "\n", "}", "\n", "return", "t", ",", "nil", "\n", "}" ]
// makeHTTPRequest hits the HTTP GET endpoint for the team data.
[ "makeHTTPRequest", "hits", "the", "HTTP", "GET", "endpoint", "for", "the", "team", "data", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L672-L685
160,004
keybase/client
go/teams/ftl.go
checkPrevs
func (f *FastTeamChainLoader) checkPrevs(m libkb.MetaContext, arg fastLoadArg, last *keybase1.LinkTriple, newLinks []*ChainLinkUnpacked) (err error) { if len(newLinks) == 0 { return nil } var prev keybase1.LinkTriple if last != nil { prev = *last } cmpHash := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { // not ideal to have to export here, but it simplifies the code. prevex := link.Prev().Export() if prev.LinkID.IsNil() && prevex.IsNil() { return nil } if prev.LinkID.IsNil() || prevex.IsNil() { m.Debug("Bad prev nil/non-nil pointer check at seqno %d: (prev=%v vs curr=%v)", link.Seqno(), prev.LinkID.IsNil(), prevex.IsNil()) return NewInvalidLink(link, "bad nil/non-nil prev pointer comparison") } if !prev.LinkID.Eq(prevex) { m.Debug("Bad prev comparison at seqno %d: %s != %s", prev.LinkID, prevex) return NewInvalidLink(link, "bad prev pointer") } return nil } cmpSeqnos := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { if prev.Seqno+1 != link.Seqno() { m.Debug("Bad sequence violation: %d+1 != %d", prev.Seqno, link.Seqno()) return NewInvalidLink(link, "seqno violation") } return checkSeqType(m, arg, link) } cmp := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { err = cmpHash(prev, link) if err != nil { return err } return cmpSeqnos(prev, link) } for _, link := range newLinks { // We might have gotten some links from the past just for the purposes of expanding // previous links that were stubbed. We don't need to check prevs on them, since // we previously did. if last != nil && last.Seqno >= link.Seqno() { continue } err := cmp(prev, link) if err != nil { return err } prev = link.LinkTriple() } return nil }
go
func (f *FastTeamChainLoader) checkPrevs(m libkb.MetaContext, arg fastLoadArg, last *keybase1.LinkTriple, newLinks []*ChainLinkUnpacked) (err error) { if len(newLinks) == 0 { return nil } var prev keybase1.LinkTriple if last != nil { prev = *last } cmpHash := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { // not ideal to have to export here, but it simplifies the code. prevex := link.Prev().Export() if prev.LinkID.IsNil() && prevex.IsNil() { return nil } if prev.LinkID.IsNil() || prevex.IsNil() { m.Debug("Bad prev nil/non-nil pointer check at seqno %d: (prev=%v vs curr=%v)", link.Seqno(), prev.LinkID.IsNil(), prevex.IsNil()) return NewInvalidLink(link, "bad nil/non-nil prev pointer comparison") } if !prev.LinkID.Eq(prevex) { m.Debug("Bad prev comparison at seqno %d: %s != %s", prev.LinkID, prevex) return NewInvalidLink(link, "bad prev pointer") } return nil } cmpSeqnos := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { if prev.Seqno+1 != link.Seqno() { m.Debug("Bad sequence violation: %d+1 != %d", prev.Seqno, link.Seqno()) return NewInvalidLink(link, "seqno violation") } return checkSeqType(m, arg, link) } cmp := func(prev keybase1.LinkTriple, link *ChainLinkUnpacked) (err error) { err = cmpHash(prev, link) if err != nil { return err } return cmpSeqnos(prev, link) } for _, link := range newLinks { // We might have gotten some links from the past just for the purposes of expanding // previous links that were stubbed. We don't need to check prevs on them, since // we previously did. if last != nil && last.Seqno >= link.Seqno() { continue } err := cmp(prev, link) if err != nil { return err } prev = link.LinkTriple() } return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "checkPrevs", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "last", "*", "keybase1", ".", "LinkTriple", ",", "newLinks", "[", "]", "*", "ChainLinkUnpacked", ")", "(", "err", "error", ")", "{", "if", "len", "(", "newLinks", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "var", "prev", "keybase1", ".", "LinkTriple", "\n", "if", "last", "!=", "nil", "{", "prev", "=", "*", "last", "\n", "}", "\n\n", "cmpHash", ":=", "func", "(", "prev", "keybase1", ".", "LinkTriple", ",", "link", "*", "ChainLinkUnpacked", ")", "(", "err", "error", ")", "{", "// not ideal to have to export here, but it simplifies the code.", "prevex", ":=", "link", ".", "Prev", "(", ")", ".", "Export", "(", ")", "\n\n", "if", "prev", ".", "LinkID", ".", "IsNil", "(", ")", "&&", "prevex", ".", "IsNil", "(", ")", "{", "return", "nil", "\n", "}", "\n", "if", "prev", ".", "LinkID", ".", "IsNil", "(", ")", "||", "prevex", ".", "IsNil", "(", ")", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "link", ".", "Seqno", "(", ")", ",", "prev", ".", "LinkID", ".", "IsNil", "(", ")", ",", "prevex", ".", "IsNil", "(", ")", ")", "\n", "return", "NewInvalidLink", "(", "link", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "!", "prev", ".", "LinkID", ".", "Eq", "(", "prevex", ")", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "prev", ".", "LinkID", ",", "prevex", ")", "\n", "return", "NewInvalidLink", "(", "link", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "cmpSeqnos", ":=", "func", "(", "prev", "keybase1", ".", "LinkTriple", ",", "link", "*", "ChainLinkUnpacked", ")", "(", "err", "error", ")", "{", "if", "prev", ".", "Seqno", "+", "1", "!=", "link", ".", "Seqno", "(", ")", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "prev", ".", "Seqno", ",", "link", ".", "Seqno", "(", ")", ")", "\n", "return", "NewInvalidLink", "(", "link", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "checkSeqType", "(", "m", ",", "arg", ",", "link", ")", "\n", "}", "\n\n", "cmp", ":=", "func", "(", "prev", "keybase1", ".", "LinkTriple", ",", "link", "*", "ChainLinkUnpacked", ")", "(", "err", "error", ")", "{", "err", "=", "cmpHash", "(", "prev", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "cmpSeqnos", "(", "prev", ",", "link", ")", "\n", "}", "\n\n", "for", "_", ",", "link", ":=", "range", "newLinks", "{", "// We might have gotten some links from the past just for the purposes of expanding", "// previous links that were stubbed. We don't need to check prevs on them, since", "// we previously did.", "if", "last", "!=", "nil", "&&", "last", ".", "Seqno", ">=", "link", ".", "Seqno", "(", ")", "{", "continue", "\n", "}", "\n", "err", ":=", "cmp", "(", "prev", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "prev", "=", "link", ".", "LinkTriple", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkPrevs checks the previous pointers on the new links that came down from the server. It // only checks prevs for links that are newer than the last link gotten in this chain. // We assume the rest are expanding hashes for links we've previously downloaded.
[ "checkPrevs", "checks", "the", "previous", "pointers", "on", "the", "new", "links", "that", "came", "down", "from", "the", "server", ".", "It", "only", "checks", "prevs", "for", "links", "that", "are", "newer", "than", "the", "last", "link", "gotten", "in", "this", "chain", ".", "We", "assume", "the", "rest", "are", "expanding", "hashes", "for", "links", "we", "ve", "previously", "downloaded", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L835-L894
160,005
keybase/client
go/teams/ftl.go
audit
func (f *FastTeamChainLoader) audit(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData) (err error) { head, ok := state.Chain.MerkleInfo[1] if !ok { return NewAuditError("cannot run audit without merkle info for head") } last := state.Chain.Last if last == nil { return NewAuditError("cannot run audit, no last chain data") } return m.G().GetTeamAuditor().AuditTeam(m, arg.ID, arg.Public, head.Seqno, state.Chain.LinkIDs, last.Seqno) }
go
func (f *FastTeamChainLoader) audit(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData) (err error) { head, ok := state.Chain.MerkleInfo[1] if !ok { return NewAuditError("cannot run audit without merkle info for head") } last := state.Chain.Last if last == nil { return NewAuditError("cannot run audit, no last chain data") } return m.G().GetTeamAuditor().AuditTeam(m, arg.ID, arg.Public, head.Seqno, state.Chain.LinkIDs, last.Seqno) }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "audit", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "state", "*", "keybase1", ".", "FastTeamData", ")", "(", "err", "error", ")", "{", "head", ",", "ok", ":=", "state", ".", "Chain", ".", "MerkleInfo", "[", "1", "]", "\n", "if", "!", "ok", "{", "return", "NewAuditError", "(", "\"", "\"", ")", "\n", "}", "\n", "last", ":=", "state", ".", "Chain", ".", "Last", "\n", "if", "last", "==", "nil", "{", "return", "NewAuditError", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "m", ".", "G", "(", ")", ".", "GetTeamAuditor", "(", ")", ".", "AuditTeam", "(", "m", ",", "arg", ".", "ID", ",", "arg", ".", "Public", ",", "head", ".", "Seqno", ",", "state", ".", "Chain", ".", "LinkIDs", ",", "last", ".", "Seqno", ")", "\n", "}" ]
// audit runs probabilistic merkle tree audit on the new links, to make sure that the server isn't // running odd-even-style attacks against members in a group.
[ "audit", "runs", "probabilistic", "merkle", "tree", "audit", "on", "the", "new", "links", "to", "make", "sure", "that", "the", "server", "isn", "t", "running", "odd", "-", "even", "-", "style", "attacks", "against", "members", "in", "a", "group", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L898-L908
160,006
keybase/client
go/teams/ftl.go
readMerkleRoot
func readMerkleRoot(m libkb.MetaContext, link *ChainLinkUnpacked) (*keybase1.MerkleRootV2, error) { if link.inner == nil { return nil, nil } ret := link.inner.Body.MerkleRoot.ToMerkleRootV2() return &ret, nil }
go
func readMerkleRoot(m libkb.MetaContext, link *ChainLinkUnpacked) (*keybase1.MerkleRootV2, error) { if link.inner == nil { return nil, nil } ret := link.inner.Body.MerkleRoot.ToMerkleRootV2() return &ret, nil }
[ "func", "readMerkleRoot", "(", "m", "libkb", ".", "MetaContext", ",", "link", "*", "ChainLinkUnpacked", ")", "(", "*", "keybase1", ".", "MerkleRootV2", ",", "error", ")", "{", "if", "link", ".", "inner", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "ret", ":=", "link", ".", "inner", ".", "Body", ".", "MerkleRoot", ".", "ToMerkleRootV2", "(", ")", "\n", "return", "&", "ret", ",", "nil", "\n", "}" ]
// readMerkleRoot reads the merkle root out of the link if this link is unstubbed.
[ "readMerkleRoot", "reads", "the", "merkle", "root", "out", "of", "the", "link", "if", "this", "link", "is", "unstubbed", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L942-L948
160,007
keybase/client
go/teams/ftl.go
readPerTeamKey
func readPerTeamKey(m libkb.MetaContext, link *ChainLinkUnpacked) (ret *keybase1.PerTeamKey, err error) { if link.inner == nil || link.inner.Body.Team == nil || link.inner.Body.Team.PerTeamKey == nil { return nil, nil } ptk := link.inner.Body.Team.PerTeamKey return &keybase1.PerTeamKey{ Gen: ptk.Generation, Seqno: link.Seqno(), SigKID: ptk.SigKID, EncKID: ptk.EncKID, }, nil }
go
func readPerTeamKey(m libkb.MetaContext, link *ChainLinkUnpacked) (ret *keybase1.PerTeamKey, err error) { if link.inner == nil || link.inner.Body.Team == nil || link.inner.Body.Team.PerTeamKey == nil { return nil, nil } ptk := link.inner.Body.Team.PerTeamKey return &keybase1.PerTeamKey{ Gen: ptk.Generation, Seqno: link.Seqno(), SigKID: ptk.SigKID, EncKID: ptk.EncKID, }, nil }
[ "func", "readPerTeamKey", "(", "m", "libkb", ".", "MetaContext", ",", "link", "*", "ChainLinkUnpacked", ")", "(", "ret", "*", "keybase1", ".", "PerTeamKey", ",", "err", "error", ")", "{", "if", "link", ".", "inner", "==", "nil", "||", "link", ".", "inner", ".", "Body", ".", "Team", "==", "nil", "||", "link", ".", "inner", ".", "Body", ".", "Team", ".", "PerTeamKey", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "ptk", ":=", "link", ".", "inner", ".", "Body", ".", "Team", ".", "PerTeamKey", "\n", "return", "&", "keybase1", ".", "PerTeamKey", "{", "Gen", ":", "ptk", ".", "Generation", ",", "Seqno", ":", "link", ".", "Seqno", "(", ")", ",", "SigKID", ":", "ptk", ".", "SigKID", ",", "EncKID", ":", "ptk", ".", "EncKID", ",", "}", ",", "nil", "\n", "}" ]
// readPerTeamKey reads a PerTeamKey section, if it exists, out of the given unpacked chainlink.
[ "readPerTeamKey", "reads", "a", "PerTeamKey", "section", "if", "it", "exists", "out", "of", "the", "given", "unpacked", "chainlink", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1006-L1018
160,008
keybase/client
go/teams/ftl.go
putLinks
func (f *FastTeamChainLoader) putLinks(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, newLinks []*ChainLinkUnpacked) (err error) { if len(newLinks) == 0 { return nil } for _, link := range newLinks { existing, ok := state.Chain.LinkIDs[link.Seqno()] linkID := link.LinkID().Export() if ok { // NOTE! This is a crucial check, since we might have checked prev's on this link // in a previous run on the chain. We have to make sure an unstubbed link is // consistent with that previous check. See checkPrevs for when we skip // checking prevs in such a case, and need to check here for linkID equality. if !linkID.Eq(existing) { return NewInvalidLink(link, "list doesn't match previously cached link") } } else { state.Chain.LinkIDs[link.Seqno()] = linkID } dp, err := readDownPointer(m, link) if err != nil { return err } if dp != nil { state.Chain.DownPointers[link.Seqno()] = *dp } up, err := readUpPointer(m, arg, link) if err != nil { return err } if up != nil && (state.Chain.LastUpPointer == nil || state.Chain.LastUpPointer.OurSeqno < up.OurSeqno) { state.Chain.LastUpPointer = up } ptk, err := readPerTeamKey(m, link) if err != nil { return err } if ptk != nil { state.Chain.PerTeamKeys[ptk.Gen] = *ptk } merkleRoot, err := readMerkleRoot(m, link) if err != nil { return err } if merkleRoot != nil { state.Chain.MerkleInfo[link.Seqno()] = *merkleRoot } } newLast := newLinks[len(newLinks)-1] if state.Chain.Last == nil || state.Chain.Last.Seqno < newLast.Seqno() { tmp := newLast.LinkTriple() state.Chain.Last = &tmp } return nil }
go
func (f *FastTeamChainLoader) putLinks(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, newLinks []*ChainLinkUnpacked) (err error) { if len(newLinks) == 0 { return nil } for _, link := range newLinks { existing, ok := state.Chain.LinkIDs[link.Seqno()] linkID := link.LinkID().Export() if ok { // NOTE! This is a crucial check, since we might have checked prev's on this link // in a previous run on the chain. We have to make sure an unstubbed link is // consistent with that previous check. See checkPrevs for when we skip // checking prevs in such a case, and need to check here for linkID equality. if !linkID.Eq(existing) { return NewInvalidLink(link, "list doesn't match previously cached link") } } else { state.Chain.LinkIDs[link.Seqno()] = linkID } dp, err := readDownPointer(m, link) if err != nil { return err } if dp != nil { state.Chain.DownPointers[link.Seqno()] = *dp } up, err := readUpPointer(m, arg, link) if err != nil { return err } if up != nil && (state.Chain.LastUpPointer == nil || state.Chain.LastUpPointer.OurSeqno < up.OurSeqno) { state.Chain.LastUpPointer = up } ptk, err := readPerTeamKey(m, link) if err != nil { return err } if ptk != nil { state.Chain.PerTeamKeys[ptk.Gen] = *ptk } merkleRoot, err := readMerkleRoot(m, link) if err != nil { return err } if merkleRoot != nil { state.Chain.MerkleInfo[link.Seqno()] = *merkleRoot } } newLast := newLinks[len(newLinks)-1] if state.Chain.Last == nil || state.Chain.Last.Seqno < newLast.Seqno() { tmp := newLast.LinkTriple() state.Chain.Last = &tmp } return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "putLinks", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "state", "*", "keybase1", ".", "FastTeamData", ",", "newLinks", "[", "]", "*", "ChainLinkUnpacked", ")", "(", "err", "error", ")", "{", "if", "len", "(", "newLinks", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "for", "_", ",", "link", ":=", "range", "newLinks", "{", "existing", ",", "ok", ":=", "state", ".", "Chain", ".", "LinkIDs", "[", "link", ".", "Seqno", "(", ")", "]", "\n", "linkID", ":=", "link", ".", "LinkID", "(", ")", ".", "Export", "(", ")", "\n", "if", "ok", "{", "// NOTE! This is a crucial check, since we might have checked prev's on this link", "// in a previous run on the chain. We have to make sure an unstubbed link is", "// consistent with that previous check. See checkPrevs for when we skip", "// checking prevs in such a case, and need to check here for linkID equality.", "if", "!", "linkID", ".", "Eq", "(", "existing", ")", "{", "return", "NewInvalidLink", "(", "link", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "{", "state", ".", "Chain", ".", "LinkIDs", "[", "link", ".", "Seqno", "(", ")", "]", "=", "linkID", "\n", "}", "\n", "dp", ",", "err", ":=", "readDownPointer", "(", "m", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "dp", "!=", "nil", "{", "state", ".", "Chain", ".", "DownPointers", "[", "link", ".", "Seqno", "(", ")", "]", "=", "*", "dp", "\n", "}", "\n", "up", ",", "err", ":=", "readUpPointer", "(", "m", ",", "arg", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "up", "!=", "nil", "&&", "(", "state", ".", "Chain", ".", "LastUpPointer", "==", "nil", "||", "state", ".", "Chain", ".", "LastUpPointer", ".", "OurSeqno", "<", "up", ".", "OurSeqno", ")", "{", "state", ".", "Chain", ".", "LastUpPointer", "=", "up", "\n", "}", "\n", "ptk", ",", "err", ":=", "readPerTeamKey", "(", "m", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "ptk", "!=", "nil", "{", "state", ".", "Chain", ".", "PerTeamKeys", "[", "ptk", ".", "Gen", "]", "=", "*", "ptk", "\n", "}", "\n", "merkleRoot", ",", "err", ":=", "readMerkleRoot", "(", "m", ",", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "merkleRoot", "!=", "nil", "{", "state", ".", "Chain", ".", "MerkleInfo", "[", "link", ".", "Seqno", "(", ")", "]", "=", "*", "merkleRoot", "\n", "}", "\n", "}", "\n", "newLast", ":=", "newLinks", "[", "len", "(", "newLinks", ")", "-", "1", "]", "\n", "if", "state", ".", "Chain", ".", "Last", "==", "nil", "||", "state", ".", "Chain", ".", "Last", ".", "Seqno", "<", "newLast", ".", "Seqno", "(", ")", "{", "tmp", ":=", "newLast", ".", "LinkTriple", "(", ")", "\n", "state", ".", "Chain", ".", "Last", "=", "&", "tmp", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// putLinks takes the links we just downloaded from the server, and stores them to the state. // It also fills in unstubbed fields for those links that have come back with payloads that // were previously stubbed. There are several error cases that can come up, when reading down // or up pointers from the reply.
[ "putLinks", "takes", "the", "links", "we", "just", "downloaded", "from", "the", "server", "and", "stores", "them", "to", "the", "state", ".", "It", "also", "fills", "in", "unstubbed", "fields", "for", "those", "links", "that", "have", "come", "back", "with", "payloads", "that", "were", "previously", "stubbed", ".", "There", "are", "several", "error", "cases", "that", "can", "come", "up", "when", "reading", "down", "or", "up", "pointers", "from", "the", "reply", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1024-L1078
160,009
keybase/client
go/teams/ftl.go
putRKMs
func (f *FastTeamChainLoader) putRKMs(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, rkms []keybase1.ReaderKeyMask) (err error) { for _, rkm := range rkms { if _, ok := state.ReaderKeyMasks[rkm.Application]; !ok { state.ReaderKeyMasks[rkm.Application] = make(map[keybase1.PerTeamKeyGeneration]keybase1.MaskB64) } state.ReaderKeyMasks[rkm.Application][rkm.Generation] = rkm.Mask } return nil }
go
func (f *FastTeamChainLoader) putRKMs(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, rkms []keybase1.ReaderKeyMask) (err error) { for _, rkm := range rkms { if _, ok := state.ReaderKeyMasks[rkm.Application]; !ok { state.ReaderKeyMasks[rkm.Application] = make(map[keybase1.PerTeamKeyGeneration]keybase1.MaskB64) } state.ReaderKeyMasks[rkm.Application][rkm.Generation] = rkm.Mask } return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "putRKMs", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "state", "*", "keybase1", ".", "FastTeamData", ",", "rkms", "[", "]", "keybase1", ".", "ReaderKeyMask", ")", "(", "err", "error", ")", "{", "for", "_", ",", "rkm", ":=", "range", "rkms", "{", "if", "_", ",", "ok", ":=", "state", ".", "ReaderKeyMasks", "[", "rkm", ".", "Application", "]", ";", "!", "ok", "{", "state", ".", "ReaderKeyMasks", "[", "rkm", ".", "Application", "]", "=", "make", "(", "map", "[", "keybase1", ".", "PerTeamKeyGeneration", "]", "keybase1", ".", "MaskB64", ")", "\n", "}", "\n", "state", ".", "ReaderKeyMasks", "[", "rkm", ".", "Application", "]", "[", "rkm", ".", "Generation", "]", "=", "rkm", ".", "Mask", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// putRKMs stores the new reader key masks loaded from the server to the state structure.
[ "putRKMs", "stores", "the", "new", "reader", "key", "masks", "loaded", "from", "the", "server", "to", "the", "state", "structure", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1081-L1089
160,010
keybase/client
go/teams/ftl.go
putSeeds
func (f *FastTeamChainLoader) putSeeds(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, latestKeyGen keybase1.PerTeamKeyGeneration, seeds []keybase1.PerTeamKeySeed) (err error) { for i, seed := range seeds { state.PerTeamKeySeedsUnverified[latestKeyGen-keybase1.PerTeamKeyGeneration(len(seeds)-i-1)] = seed } // We might have gotten back 0 seeds from the server, so don't overwrite a valid LatestKeyGeneration // with 0 in that case. if latestKeyGen > state.LatestKeyGeneration { state.LatestKeyGeneration = latestKeyGen } return nil }
go
func (f *FastTeamChainLoader) putSeeds(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, latestKeyGen keybase1.PerTeamKeyGeneration, seeds []keybase1.PerTeamKeySeed) (err error) { for i, seed := range seeds { state.PerTeamKeySeedsUnverified[latestKeyGen-keybase1.PerTeamKeyGeneration(len(seeds)-i-1)] = seed } // We might have gotten back 0 seeds from the server, so don't overwrite a valid LatestKeyGeneration // with 0 in that case. if latestKeyGen > state.LatestKeyGeneration { state.LatestKeyGeneration = latestKeyGen } return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "putSeeds", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "state", "*", "keybase1", ".", "FastTeamData", ",", "latestKeyGen", "keybase1", ".", "PerTeamKeyGeneration", ",", "seeds", "[", "]", "keybase1", ".", "PerTeamKeySeed", ")", "(", "err", "error", ")", "{", "for", "i", ",", "seed", ":=", "range", "seeds", "{", "state", ".", "PerTeamKeySeedsUnverified", "[", "latestKeyGen", "-", "keybase1", ".", "PerTeamKeyGeneration", "(", "len", "(", "seeds", ")", "-", "i", "-", "1", ")", "]", "=", "seed", "\n", "}", "\n\n", "// We might have gotten back 0 seeds from the server, so don't overwrite a valid LatestKeyGeneration", "// with 0 in that case.", "if", "latestKeyGen", ">", "state", ".", "LatestKeyGeneration", "{", "state", ".", "LatestKeyGeneration", "=", "latestKeyGen", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// putSeeds stores the crypto seeds to the PeterTeamKeySeedsUnverified slot of the state. It returns // the last n seeds, counting backwards. We exploit this fact to infer the seed generations from their // order.
[ "putSeeds", "stores", "the", "crypto", "seeds", "to", "the", "PeterTeamKeySeedsUnverified", "slot", "of", "the", "state", ".", "It", "returns", "the", "last", "n", "seeds", "counting", "backwards", ".", "We", "exploit", "this", "fact", "to", "infer", "the", "seed", "generations", "from", "their", "order", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1094-L1105
160,011
keybase/client
go/teams/ftl.go
mutateState
func (f *FastTeamChainLoader) mutateState(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, groceries *groceries) (err error) { err = f.putName(m, arg, state, groceries.newLinks) if err != nil { return err } err = f.putLinks(m, arg, state, groceries.newLinks) if err != nil { return err } err = f.putRKMs(m, arg, state, groceries.rkms) if err != nil { return err } err = f.putSeeds(m, arg, state, groceries.latestKeyGen, groceries.seeds) if err != nil { return err } err = f.putMetadata(m, arg, state) if err != nil { return err } return nil }
go
func (f *FastTeamChainLoader) mutateState(m libkb.MetaContext, arg fastLoadArg, state *keybase1.FastTeamData, groceries *groceries) (err error) { err = f.putName(m, arg, state, groceries.newLinks) if err != nil { return err } err = f.putLinks(m, arg, state, groceries.newLinks) if err != nil { return err } err = f.putRKMs(m, arg, state, groceries.rkms) if err != nil { return err } err = f.putSeeds(m, arg, state, groceries.latestKeyGen, groceries.seeds) if err != nil { return err } err = f.putMetadata(m, arg, state) if err != nil { return err } return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "mutateState", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ",", "state", "*", "keybase1", ".", "FastTeamData", ",", "groceries", "*", "groceries", ")", "(", "err", "error", ")", "{", "err", "=", "f", ".", "putName", "(", "m", ",", "arg", ",", "state", ",", "groceries", ".", "newLinks", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "f", ".", "putLinks", "(", "m", ",", "arg", ",", "state", ",", "groceries", ".", "newLinks", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "f", ".", "putRKMs", "(", "m", ",", "arg", ",", "state", ",", "groceries", ".", "rkms", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "f", ".", "putSeeds", "(", "m", ",", "arg", ",", "state", ",", "groceries", ".", "latestKeyGen", ",", "groceries", ".", "seeds", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "f", ".", "putMetadata", "(", "m", ",", "arg", ",", "state", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// mutateState takes the groceries fetched from the server and applies them to our current state.
[ "mutateState", "takes", "the", "groceries", "fetched", "from", "the", "server", "and", "applies", "them", "to", "our", "current", "state", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1120-L1143
160,012
keybase/client
go/teams/ftl.go
makeState
func makeState(arg fastLoadArg, s *keybase1.FastTeamData) *keybase1.FastTeamData { if s != nil { tmp := s.DeepCopy() return &tmp } return &keybase1.FastTeamData{ PerTeamKeySeedsUnverified: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKeySeed), ReaderKeyMasks: make(map[keybase1.TeamApplication](map[keybase1.PerTeamKeyGeneration]keybase1.MaskB64)), Chain: keybase1.FastTeamSigChainState{ ID: arg.ID, Public: arg.Public, PerTeamKeys: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKey), PerTeamKeySeedsVerified: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKeySeed), DownPointers: make(map[keybase1.Seqno]keybase1.DownPointer), LinkIDs: make(map[keybase1.Seqno]keybase1.LinkID), MerkleInfo: make(map[keybase1.Seqno]keybase1.MerkleRootV2), }, } }
go
func makeState(arg fastLoadArg, s *keybase1.FastTeamData) *keybase1.FastTeamData { if s != nil { tmp := s.DeepCopy() return &tmp } return &keybase1.FastTeamData{ PerTeamKeySeedsUnverified: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKeySeed), ReaderKeyMasks: make(map[keybase1.TeamApplication](map[keybase1.PerTeamKeyGeneration]keybase1.MaskB64)), Chain: keybase1.FastTeamSigChainState{ ID: arg.ID, Public: arg.Public, PerTeamKeys: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKey), PerTeamKeySeedsVerified: make(map[keybase1.PerTeamKeyGeneration]keybase1.PerTeamKeySeed), DownPointers: make(map[keybase1.Seqno]keybase1.DownPointer), LinkIDs: make(map[keybase1.Seqno]keybase1.LinkID), MerkleInfo: make(map[keybase1.Seqno]keybase1.MerkleRootV2), }, } }
[ "func", "makeState", "(", "arg", "fastLoadArg", ",", "s", "*", "keybase1", ".", "FastTeamData", ")", "*", "keybase1", ".", "FastTeamData", "{", "if", "s", "!=", "nil", "{", "tmp", ":=", "s", ".", "DeepCopy", "(", ")", "\n", "return", "&", "tmp", "\n", "}", "\n", "return", "&", "keybase1", ".", "FastTeamData", "{", "PerTeamKeySeedsUnverified", ":", "make", "(", "map", "[", "keybase1", ".", "PerTeamKeyGeneration", "]", "keybase1", ".", "PerTeamKeySeed", ")", ",", "ReaderKeyMasks", ":", "make", "(", "map", "[", "keybase1", ".", "TeamApplication", "]", "(", "map", "[", "keybase1", ".", "PerTeamKeyGeneration", "]", "keybase1", ".", "MaskB64", ")", ")", ",", "Chain", ":", "keybase1", ".", "FastTeamSigChainState", "{", "ID", ":", "arg", ".", "ID", ",", "Public", ":", "arg", ".", "Public", ",", "PerTeamKeys", ":", "make", "(", "map", "[", "keybase1", ".", "PerTeamKeyGeneration", "]", "keybase1", ".", "PerTeamKey", ")", ",", "PerTeamKeySeedsVerified", ":", "make", "(", "map", "[", "keybase1", ".", "PerTeamKeyGeneration", "]", "keybase1", ".", "PerTeamKeySeed", ")", ",", "DownPointers", ":", "make", "(", "map", "[", "keybase1", ".", "Seqno", "]", "keybase1", ".", "DownPointer", ")", ",", "LinkIDs", ":", "make", "(", "map", "[", "keybase1", ".", "Seqno", "]", "keybase1", ".", "LinkID", ")", ",", "MerkleInfo", ":", "make", "(", "map", "[", "keybase1", ".", "Seqno", "]", "keybase1", ".", "MerkleRootV2", ")", ",", "}", ",", "}", "\n", "}" ]
// makeState does a clone on a non-nil state, or makes a new state if nil.
[ "makeState", "does", "a", "clone", "on", "a", "non", "-", "nil", "state", "or", "makes", "a", "new", "state", "if", "nil", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1146-L1164
160,013
keybase/client
go/teams/ftl.go
updateCache
func (f *FastTeamChainLoader) updateCache(m libkb.MetaContext, state *keybase1.FastTeamData) { f.storage.Put(m, state) }
go
func (f *FastTeamChainLoader) updateCache(m libkb.MetaContext, state *keybase1.FastTeamData) { f.storage.Put(m, state) }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "updateCache", "(", "m", "libkb", ".", "MetaContext", ",", "state", "*", "keybase1", ".", "FastTeamData", ")", "{", "f", ".", "storage", ".", "Put", "(", "m", ",", "state", ")", "\n", "}" ]
// updateCache puts the new version of the state into the cache on the team's ID.
[ "updateCache", "puts", "the", "new", "version", "of", "the", "state", "into", "the", "cache", "on", "the", "team", "s", "ID", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1217-L1219
160,014
keybase/client
go/teams/ftl.go
loadLocked
func (f *FastTeamChainLoader) loadLocked(m libkb.MetaContext, arg fastLoadArg) (res *fastLoadRes, err error) { state := f.findStateInCache(m, arg.ID) var shoppingList shoppingList if state != nil { f.computeWithPreviousState(m, &shoppingList, arg, state) if shoppingList.isEmpty() { return f.toResult(m, arg, state) } } else { shoppingList.computeFreshLoad(m, arg) } m.Debug("FastTeamChainLoader#loadLocked: computed shopping list: %+v", shoppingList) var newState *keybase1.FastTeamData newState, err = f.refresh(m, arg, state, shoppingList) if err != nil { return nil, err } // If newState == nil, that means that no updates were required, and the old state // is fine, we just need to update the cachedAt time. If newState is non-nil, // then we use if for our state going forward. if newState == nil { setCachedAtToNow(m, state) } else { state = newState } // Always update the cache, even if we're just bumping the cachedAt time. f.updateCache(m, state) return f.toResult(m, arg, state) }
go
func (f *FastTeamChainLoader) loadLocked(m libkb.MetaContext, arg fastLoadArg) (res *fastLoadRes, err error) { state := f.findStateInCache(m, arg.ID) var shoppingList shoppingList if state != nil { f.computeWithPreviousState(m, &shoppingList, arg, state) if shoppingList.isEmpty() { return f.toResult(m, arg, state) } } else { shoppingList.computeFreshLoad(m, arg) } m.Debug("FastTeamChainLoader#loadLocked: computed shopping list: %+v", shoppingList) var newState *keybase1.FastTeamData newState, err = f.refresh(m, arg, state, shoppingList) if err != nil { return nil, err } // If newState == nil, that means that no updates were required, and the old state // is fine, we just need to update the cachedAt time. If newState is non-nil, // then we use if for our state going forward. if newState == nil { setCachedAtToNow(m, state) } else { state = newState } // Always update the cache, even if we're just bumping the cachedAt time. f.updateCache(m, state) return f.toResult(m, arg, state) }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "loadLocked", "(", "m", "libkb", ".", "MetaContext", ",", "arg", "fastLoadArg", ")", "(", "res", "*", "fastLoadRes", ",", "err", "error", ")", "{", "state", ":=", "f", ".", "findStateInCache", "(", "m", ",", "arg", ".", "ID", ")", "\n\n", "var", "shoppingList", "shoppingList", "\n", "if", "state", "!=", "nil", "{", "f", ".", "computeWithPreviousState", "(", "m", ",", "&", "shoppingList", ",", "arg", ",", "state", ")", "\n", "if", "shoppingList", ".", "isEmpty", "(", ")", "{", "return", "f", ".", "toResult", "(", "m", ",", "arg", ",", "state", ")", "\n", "}", "\n", "}", "else", "{", "shoppingList", ".", "computeFreshLoad", "(", "m", ",", "arg", ")", "\n", "}", "\n\n", "m", ".", "Debug", "(", "\"", "\"", ",", "shoppingList", ")", "\n\n", "var", "newState", "*", "keybase1", ".", "FastTeamData", "\n", "newState", ",", "err", "=", "f", ".", "refresh", "(", "m", ",", "arg", ",", "state", ",", "shoppingList", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// If newState == nil, that means that no updates were required, and the old state", "// is fine, we just need to update the cachedAt time. If newState is non-nil,", "// then we use if for our state going forward.", "if", "newState", "==", "nil", "{", "setCachedAtToNow", "(", "m", ",", "state", ")", "\n", "}", "else", "{", "state", "=", "newState", "\n", "}", "\n", "// Always update the cache, even if we're just bumping the cachedAt time.", "f", ".", "updateCache", "(", "m", ",", "state", ")", "\n\n", "return", "f", ".", "toResult", "(", "m", ",", "arg", ",", "state", ")", "\n", "}" ]
// loadLocked is the inner loop for loading team. Should be called when holding the lock // this teamID.
[ "loadLocked", "is", "the", "inner", "loop", "for", "loading", "team", ".", "Should", "be", "called", "when", "holding", "the", "lock", "this", "teamID", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1223-L1257
160,015
keybase/client
go/teams/ftl.go
OnLogout
func (f *FastTeamChainLoader) OnLogout(mctx libkb.MetaContext) error { f.storage.clearMem() f.featureFlagGate.Clear() return nil }
go
func (f *FastTeamChainLoader) OnLogout(mctx libkb.MetaContext) error { f.storage.clearMem() f.featureFlagGate.Clear() return nil }
[ "func", "(", "f", "*", "FastTeamChainLoader", ")", "OnLogout", "(", "mctx", "libkb", ".", "MetaContext", ")", "error", "{", "f", ".", "storage", ".", "clearMem", "(", ")", "\n", "f", ".", "featureFlagGate", ".", "Clear", "(", ")", "\n", "return", "nil", "\n", "}" ]
// OnLogout is called when the user logs out, which purges the LRU.
[ "OnLogout", "is", "called", "when", "the", "user", "logs", "out", "which", "purges", "the", "LRU", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/ftl.go#L1260-L1264
160,016
keybase/client
go/spotty/spotty_nix.go
Discover
func Discover() (string, error) { var sstat syscall.Stat_t if err := syscall.Fstat(0, &sstat); err != nil { return "", err } res, err := findFileIn(&sstat, "/dev", regexp.MustCompile(`^tty[A-Za-z0-9]+$`)) if err != nil { return "", err } if len(res) > 0 { return res, nil } res, err = findFileIn(&sstat, "/dev/pts", regexp.MustCompile(`^[0-9]+$`)) return res, err }
go
func Discover() (string, error) { var sstat syscall.Stat_t if err := syscall.Fstat(0, &sstat); err != nil { return "", err } res, err := findFileIn(&sstat, "/dev", regexp.MustCompile(`^tty[A-Za-z0-9]+$`)) if err != nil { return "", err } if len(res) > 0 { return res, nil } res, err = findFileIn(&sstat, "/dev/pts", regexp.MustCompile(`^[0-9]+$`)) return res, err }
[ "func", "Discover", "(", ")", "(", "string", ",", "error", ")", "{", "var", "sstat", "syscall", ".", "Stat_t", "\n", "if", "err", ":=", "syscall", ".", "Fstat", "(", "0", ",", "&", "sstat", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "res", ",", "err", ":=", "findFileIn", "(", "&", "sstat", ",", "\"", "\"", ",", "regexp", ".", "MustCompile", "(", "`^tty[A-Za-z0-9]+$`", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "res", ",", "nil", "\n", "}", "\n", "res", ",", "err", "=", "findFileIn", "(", "&", "sstat", ",", "\"", "\"", ",", "regexp", ".", "MustCompile", "(", "`^[0-9]+$`", ")", ")", "\n", "return", "res", ",", "err", "\n", "}" ]
// Discover which named TTY we have open as FD=0. Will return empty string if nothing // was found, and a non-nil error if there was a problem. Will noop on Windows.
[ "Discover", "which", "named", "TTY", "we", "have", "open", "as", "FD", "=", "0", ".", "Will", "return", "empty", "string", "if", "nothing", "was", "found", "and", "a", "non", "-", "nil", "error", "if", "there", "was", "a", "problem", ".", "Will", "noop", "on", "Windows", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/spotty/spotty_nix.go#L25-L39
160,017
keybase/client
go/install/install_darwin.go
KeybaseServiceStatus
func KeybaseServiceStatus(context Context, label string, wait time.Duration, log Log) (status keybase1.ServiceStatus) { if label == "" { status = keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} return } kbService := launchd.NewService(label) status, err := serviceStatusFromLaunchd(kbService, context.GetServiceInfoPath(), wait, log) status.BundleVersion = libkb.VersionString() if err != nil { return } if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED { return } installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus, log) status.InstallStatus = installStatus status.InstallAction = installAction status.Status = kbStatus return }
go
func KeybaseServiceStatus(context Context, label string, wait time.Duration, log Log) (status keybase1.ServiceStatus) { if label == "" { status = keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} return } kbService := launchd.NewService(label) status, err := serviceStatusFromLaunchd(kbService, context.GetServiceInfoPath(), wait, log) status.BundleVersion = libkb.VersionString() if err != nil { return } if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED { return } installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus, log) status.InstallStatus = installStatus status.InstallAction = installAction status.Status = kbStatus return }
[ "func", "KeybaseServiceStatus", "(", "context", "Context", ",", "label", "string", ",", "wait", "time", ".", "Duration", ",", "log", "Log", ")", "(", "status", "keybase1", ".", "ServiceStatus", ")", "{", "if", "label", "==", "\"", "\"", "{", "status", "=", "keybase1", ".", "ServiceStatus", "{", "Status", ":", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCServiceStatusError", ",", "\"", "\"", ")", "}", "\n", "return", "\n", "}", "\n", "kbService", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n\n", "status", ",", "err", ":=", "serviceStatusFromLaunchd", "(", "kbService", ",", "context", ".", "GetServiceInfoPath", "(", ")", ",", "wait", ",", "log", ")", "\n", "status", ".", "BundleVersion", "=", "libkb", ".", "VersionString", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "status", ".", "InstallStatus", "==", "keybase1", ".", "InstallStatus_NOT_INSTALLED", "{", "return", "\n", "}", "\n\n", "installStatus", ",", "installAction", ",", "kbStatus", ":=", "ResolveInstallStatus", "(", "status", ".", "Version", ",", "status", ".", "BundleVersion", ",", "status", ".", "LastExitStatus", ",", "log", ")", "\n", "status", ".", "InstallStatus", "=", "installStatus", "\n", "status", ".", "InstallAction", "=", "installAction", "\n", "status", ".", "Status", "=", "kbStatus", "\n", "return", "\n", "}" ]
// KeybaseServiceStatus returns service status for Keybase service
[ "KeybaseServiceStatus", "returns", "service", "status", "for", "Keybase", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L58-L79
160,018
keybase/client
go/install/install_darwin.go
KBFSServiceStatus
func KBFSServiceStatus(context Context, label string, wait time.Duration, log Log) (status keybase1.ServiceStatus) { if label == "" { status = keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} return } kbfsService := launchd.NewService(label) status, err := serviceStatusFromLaunchd(kbfsService, context.GetKBFSInfoPath(), wait, log) if err != nil { return } bundleVersion, err := KBFSBundleVersion(context, "") if err != nil { status.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error()) return } status.BundleVersion = bundleVersion if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED { return } installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus, log) status.InstallStatus = installStatus status.InstallAction = installAction status.Status = kbStatus return }
go
func KBFSServiceStatus(context Context, label string, wait time.Duration, log Log) (status keybase1.ServiceStatus) { if label == "" { status = keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} return } kbfsService := launchd.NewService(label) status, err := serviceStatusFromLaunchd(kbfsService, context.GetKBFSInfoPath(), wait, log) if err != nil { return } bundleVersion, err := KBFSBundleVersion(context, "") if err != nil { status.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error()) return } status.BundleVersion = bundleVersion if status.InstallStatus == keybase1.InstallStatus_NOT_INSTALLED { return } installStatus, installAction, kbStatus := ResolveInstallStatus(status.Version, status.BundleVersion, status.LastExitStatus, log) status.InstallStatus = installStatus status.InstallAction = installAction status.Status = kbStatus return }
[ "func", "KBFSServiceStatus", "(", "context", "Context", ",", "label", "string", ",", "wait", "time", ".", "Duration", ",", "log", "Log", ")", "(", "status", "keybase1", ".", "ServiceStatus", ")", "{", "if", "label", "==", "\"", "\"", "{", "status", "=", "keybase1", ".", "ServiceStatus", "{", "Status", ":", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCServiceStatusError", ",", "\"", "\"", ")", "}", "\n", "return", "\n", "}", "\n", "kbfsService", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n\n", "status", ",", "err", ":=", "serviceStatusFromLaunchd", "(", "kbfsService", ",", "context", ".", "GetKBFSInfoPath", "(", ")", ",", "wait", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "bundleVersion", ",", "err", ":=", "KBFSBundleVersion", "(", "context", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "status", ".", "Status", "=", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCServiceStatusError", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "status", ".", "BundleVersion", "=", "bundleVersion", "\n", "if", "status", ".", "InstallStatus", "==", "keybase1", ".", "InstallStatus_NOT_INSTALLED", "{", "return", "\n", "}", "\n\n", "installStatus", ",", "installAction", ",", "kbStatus", ":=", "ResolveInstallStatus", "(", "status", ".", "Version", ",", "status", ".", "BundleVersion", ",", "status", ".", "LastExitStatus", ",", "log", ")", "\n", "status", ".", "InstallStatus", "=", "installStatus", "\n", "status", ".", "InstallAction", "=", "installAction", "\n", "status", ".", "Status", "=", "kbStatus", "\n", "return", "\n", "}" ]
// KBFSServiceStatus returns service status for KBFS
[ "KBFSServiceStatus", "returns", "service", "status", "for", "KBFS" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L82-L108
160,019
keybase/client
go/install/install_darwin.go
UpdaterServiceStatus
func UpdaterServiceStatus(context Context, label string) keybase1.ServiceStatus { if label == "" { return keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} } serviceStatus := keybase1.ServiceStatus{Label: label} updaterService := launchd.NewService(label) status, err := updaterService.WaitForStatus(defaultLaunchdWait, 500*time.Millisecond) if err != nil { serviceStatus.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error()) return serviceStatus } if status != nil { serviceStatus.Pid = status.Pid() serviceStatus.LastExitStatus = status.LastExitStatus() } if serviceStatus.Pid != "" { serviceStatus.InstallStatus = keybase1.InstallStatus_INSTALLED serviceStatus.InstallAction = keybase1.InstallAction_NONE } else { serviceStatus.InstallStatus = keybase1.InstallStatus_NOT_INSTALLED serviceStatus.InstallAction = keybase1.InstallAction_INSTALL } serviceStatus.Status = keybase1.StatusOK("") return serviceStatus }
go
func UpdaterServiceStatus(context Context, label string) keybase1.ServiceStatus { if label == "" { return keybase1.ServiceStatus{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, "No service label")} } serviceStatus := keybase1.ServiceStatus{Label: label} updaterService := launchd.NewService(label) status, err := updaterService.WaitForStatus(defaultLaunchdWait, 500*time.Millisecond) if err != nil { serviceStatus.Status = keybase1.StatusFromCode(keybase1.StatusCode_SCServiceStatusError, err.Error()) return serviceStatus } if status != nil { serviceStatus.Pid = status.Pid() serviceStatus.LastExitStatus = status.LastExitStatus() } if serviceStatus.Pid != "" { serviceStatus.InstallStatus = keybase1.InstallStatus_INSTALLED serviceStatus.InstallAction = keybase1.InstallAction_NONE } else { serviceStatus.InstallStatus = keybase1.InstallStatus_NOT_INSTALLED serviceStatus.InstallAction = keybase1.InstallAction_INSTALL } serviceStatus.Status = keybase1.StatusOK("") return serviceStatus }
[ "func", "UpdaterServiceStatus", "(", "context", "Context", ",", "label", "string", ")", "keybase1", ".", "ServiceStatus", "{", "if", "label", "==", "\"", "\"", "{", "return", "keybase1", ".", "ServiceStatus", "{", "Status", ":", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCServiceStatusError", ",", "\"", "\"", ")", "}", "\n", "}", "\n", "serviceStatus", ":=", "keybase1", ".", "ServiceStatus", "{", "Label", ":", "label", "}", "\n", "updaterService", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n", "status", ",", "err", ":=", "updaterService", ".", "WaitForStatus", "(", "defaultLaunchdWait", ",", "500", "*", "time", ".", "Millisecond", ")", "\n", "if", "err", "!=", "nil", "{", "serviceStatus", ".", "Status", "=", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCServiceStatusError", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "serviceStatus", "\n", "}", "\n", "if", "status", "!=", "nil", "{", "serviceStatus", ".", "Pid", "=", "status", ".", "Pid", "(", ")", "\n", "serviceStatus", ".", "LastExitStatus", "=", "status", ".", "LastExitStatus", "(", ")", "\n", "}", "\n", "if", "serviceStatus", ".", "Pid", "!=", "\"", "\"", "{", "serviceStatus", ".", "InstallStatus", "=", "keybase1", ".", "InstallStatus_INSTALLED", "\n", "serviceStatus", ".", "InstallAction", "=", "keybase1", ".", "InstallAction_NONE", "\n", "}", "else", "{", "serviceStatus", ".", "InstallStatus", "=", "keybase1", ".", "InstallStatus_NOT_INSTALLED", "\n", "serviceStatus", ".", "InstallAction", "=", "keybase1", ".", "InstallAction_INSTALL", "\n", "}", "\n", "serviceStatus", ".", "Status", "=", "keybase1", ".", "StatusOK", "(", "\"", "\"", ")", "\n", "return", "serviceStatus", "\n", "}" ]
// UpdaterServiceStatus returns service status for the Updater service
[ "UpdaterServiceStatus", "returns", "service", "status", "for", "the", "Updater", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L111-L135
160,020
keybase/client
go/install/install_darwin.go
ListServices
func ListServices(context Context, wait time.Duration, log Log) (*keybase1.ServicesStatus, error) { services, err := launchd.ListServices([]string{"keybase.service", "homebrew.mxcl.keybase"}) if err != nil { return nil, err } kbfs, err := launchd.ListServices([]string{"keybase.kbfs.", "homebrew.mxcl.kbfs"}) if err != nil { return nil, err } updater, err := launchd.ListServices([]string{"keybase.updater."}) if err != nil { return nil, err } return &keybase1.ServicesStatus{ Service: serviceStatusesFromLaunchd(context, services, wait, log), Kbfs: serviceStatusesFromLaunchd(context, kbfs, wait, log), Updater: serviceStatusesFromLaunchd(context, updater, wait, log), }, nil }
go
func ListServices(context Context, wait time.Duration, log Log) (*keybase1.ServicesStatus, error) { services, err := launchd.ListServices([]string{"keybase.service", "homebrew.mxcl.keybase"}) if err != nil { return nil, err } kbfs, err := launchd.ListServices([]string{"keybase.kbfs.", "homebrew.mxcl.kbfs"}) if err != nil { return nil, err } updater, err := launchd.ListServices([]string{"keybase.updater."}) if err != nil { return nil, err } return &keybase1.ServicesStatus{ Service: serviceStatusesFromLaunchd(context, services, wait, log), Kbfs: serviceStatusesFromLaunchd(context, kbfs, wait, log), Updater: serviceStatusesFromLaunchd(context, updater, wait, log), }, nil }
[ "func", "ListServices", "(", "context", "Context", ",", "wait", "time", ".", "Duration", ",", "log", "Log", ")", "(", "*", "keybase1", ".", "ServicesStatus", ",", "error", ")", "{", "services", ",", "err", ":=", "launchd", ".", "ListServices", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "kbfs", ",", "err", ":=", "launchd", ".", "ListServices", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "updater", ",", "err", ":=", "launchd", ".", "ListServices", "(", "[", "]", "string", "{", "\"", "\"", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "keybase1", ".", "ServicesStatus", "{", "Service", ":", "serviceStatusesFromLaunchd", "(", "context", ",", "services", ",", "wait", ",", "log", ")", ",", "Kbfs", ":", "serviceStatusesFromLaunchd", "(", "context", ",", "kbfs", ",", "wait", ",", "log", ")", ",", "Updater", ":", "serviceStatusesFromLaunchd", "(", "context", ",", "updater", ",", "wait", ",", "log", ")", ",", "}", ",", "nil", "\n", "}" ]
// ListServices returns status for all services
[ "ListServices", "returns", "status", "for", "all", "services" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L200-L219
160,021
keybase/client
go/install/install_darwin.go
DefaultLaunchdEnvVars
func DefaultLaunchdEnvVars(label string) []launchd.EnvVar { return []launchd.EnvVar{ launchd.NewEnvVar("KEYBASE_LABEL", label), launchd.NewEnvVar("KEYBASE_SERVICE_TYPE", "launchd"), } }
go
func DefaultLaunchdEnvVars(label string) []launchd.EnvVar { return []launchd.EnvVar{ launchd.NewEnvVar("KEYBASE_LABEL", label), launchd.NewEnvVar("KEYBASE_SERVICE_TYPE", "launchd"), } }
[ "func", "DefaultLaunchdEnvVars", "(", "label", "string", ")", "[", "]", "launchd", ".", "EnvVar", "{", "return", "[", "]", "launchd", ".", "EnvVar", "{", "launchd", ".", "NewEnvVar", "(", "\"", "\"", ",", "label", ")", ",", "launchd", ".", "NewEnvVar", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "}", "\n", "}" ]
// DefaultLaunchdEnvVars returns default environment vars for launchd
[ "DefaultLaunchdEnvVars", "returns", "default", "environment", "vars", "for", "launchd" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L222-L227
160,022
keybase/client
go/install/install_darwin.go
DefaultUpdaterLabel
func DefaultUpdaterLabel(runMode libkb.RunMode) string { label := AppUpdaterLabel.String() if runMode != libkb.ProductionRunMode { label = label + "." + string(runMode) } return label }
go
func DefaultUpdaterLabel(runMode libkb.RunMode) string { label := AppUpdaterLabel.String() if runMode != libkb.ProductionRunMode { label = label + "." + string(runMode) } return label }
[ "func", "DefaultUpdaterLabel", "(", "runMode", "libkb", ".", "RunMode", ")", "string", "{", "label", ":=", "AppUpdaterLabel", ".", "String", "(", ")", "\n", "if", "runMode", "!=", "libkb", ".", "ProductionRunMode", "{", "label", "=", "label", "+", "\"", "\"", "+", "string", "(", "runMode", ")", "\n", "}", "\n", "return", "label", "\n", "}" ]
// DefaultUpdaterLabel returns the default label for the update service in launchd
[ "DefaultUpdaterLabel", "returns", "the", "default", "label", "for", "the", "update", "service", "in", "launchd" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L262-L268
160,023
keybase/client
go/install/install_darwin.go
NewServiceLabel
func NewServiceLabel(s string) (ServiceLabel, error) { switch s { case string(AppServiceLabel): return AppServiceLabel, nil case string(BrewServiceLabel): return BrewServiceLabel, nil case string(AppKBFSLabel): return AppKBFSLabel, nil case string(BrewKBFSLabel): return BrewKBFSLabel, nil case string(AppUpdaterLabel): return AppUpdaterLabel, nil } return UnknownLabel, fmt.Errorf("Unknown service label: %s", s) }
go
func NewServiceLabel(s string) (ServiceLabel, error) { switch s { case string(AppServiceLabel): return AppServiceLabel, nil case string(BrewServiceLabel): return BrewServiceLabel, nil case string(AppKBFSLabel): return AppKBFSLabel, nil case string(BrewKBFSLabel): return BrewKBFSLabel, nil case string(AppUpdaterLabel): return AppUpdaterLabel, nil } return UnknownLabel, fmt.Errorf("Unknown service label: %s", s) }
[ "func", "NewServiceLabel", "(", "s", "string", ")", "(", "ServiceLabel", ",", "error", ")", "{", "switch", "s", "{", "case", "string", "(", "AppServiceLabel", ")", ":", "return", "AppServiceLabel", ",", "nil", "\n", "case", "string", "(", "BrewServiceLabel", ")", ":", "return", "BrewServiceLabel", ",", "nil", "\n", "case", "string", "(", "AppKBFSLabel", ")", ":", "return", "AppKBFSLabel", ",", "nil", "\n", "case", "string", "(", "BrewKBFSLabel", ")", ":", "return", "BrewKBFSLabel", ",", "nil", "\n", "case", "string", "(", "AppUpdaterLabel", ")", ":", "return", "AppUpdaterLabel", ",", "nil", "\n", "}", "\n", "return", "UnknownLabel", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ")", "\n", "}" ]
// NewServiceLabel constructs a service label
[ "NewServiceLabel", "constructs", "a", "service", "label" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L356-L370
160,024
keybase/client
go/install/install_darwin.go
ComponentName
func (l ServiceLabel) ComponentName() ComponentName { switch l { case AppServiceLabel, BrewServiceLabel: return ComponentNameService case AppKBFSLabel, BrewKBFSLabel: return ComponentNameKBFS case AppUpdaterLabel: return ComponentNameUpdater } return ComponentNameUnknown }
go
func (l ServiceLabel) ComponentName() ComponentName { switch l { case AppServiceLabel, BrewServiceLabel: return ComponentNameService case AppKBFSLabel, BrewKBFSLabel: return ComponentNameKBFS case AppUpdaterLabel: return ComponentNameUpdater } return ComponentNameUnknown }
[ "func", "(", "l", "ServiceLabel", ")", "ComponentName", "(", ")", "ComponentName", "{", "switch", "l", "{", "case", "AppServiceLabel", ",", "BrewServiceLabel", ":", "return", "ComponentNameService", "\n", "case", "AppKBFSLabel", ",", "BrewKBFSLabel", ":", "return", "ComponentNameKBFS", "\n", "case", "AppUpdaterLabel", ":", "return", "ComponentNameUpdater", "\n", "}", "\n", "return", "ComponentNameUnknown", "\n", "}" ]
// ComponentName returns the component name for a service label
[ "ComponentName", "returns", "the", "component", "name", "for", "a", "service", "label" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L377-L387
160,025
keybase/client
go/install/install_darwin.go
ServiceStatus
func ServiceStatus(context Context, label ServiceLabel, wait time.Duration, log Log) (*keybase1.ServiceStatus, error) { switch label.ComponentName() { case ComponentNameService: st := KeybaseServiceStatus(context, string(label), wait, log) return &st, nil case ComponentNameKBFS: st := KBFSServiceStatus(context, string(label), wait, log) return &st, nil case ComponentNameUpdater: st := UpdaterServiceStatus(context, string(label)) return &st, nil default: return nil, fmt.Errorf("Invalid label: %s", label) } }
go
func ServiceStatus(context Context, label ServiceLabel, wait time.Duration, log Log) (*keybase1.ServiceStatus, error) { switch label.ComponentName() { case ComponentNameService: st := KeybaseServiceStatus(context, string(label), wait, log) return &st, nil case ComponentNameKBFS: st := KBFSServiceStatus(context, string(label), wait, log) return &st, nil case ComponentNameUpdater: st := UpdaterServiceStatus(context, string(label)) return &st, nil default: return nil, fmt.Errorf("Invalid label: %s", label) } }
[ "func", "ServiceStatus", "(", "context", "Context", ",", "label", "ServiceLabel", ",", "wait", "time", ".", "Duration", ",", "log", "Log", ")", "(", "*", "keybase1", ".", "ServiceStatus", ",", "error", ")", "{", "switch", "label", ".", "ComponentName", "(", ")", "{", "case", "ComponentNameService", ":", "st", ":=", "KeybaseServiceStatus", "(", "context", ",", "string", "(", "label", ")", ",", "wait", ",", "log", ")", "\n", "return", "&", "st", ",", "nil", "\n", "case", "ComponentNameKBFS", ":", "st", ":=", "KBFSServiceStatus", "(", "context", ",", "string", "(", "label", ")", ",", "wait", ",", "log", ")", "\n", "return", "&", "st", ",", "nil", "\n", "case", "ComponentNameUpdater", ":", "st", ":=", "UpdaterServiceStatus", "(", "context", ",", "string", "(", "label", ")", ")", "\n", "return", "&", "st", ",", "nil", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "label", ")", "\n", "}", "\n", "}" ]
// ServiceStatus returns status for a service named by label
[ "ServiceStatus", "returns", "status", "for", "a", "service", "named", "by", "label" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L390-L404
160,026
keybase/client
go/install/install_darwin.go
InstallAuto
func InstallAuto(context Context, binPath string, sourcePath string, timeout time.Duration, log Log) keybase1.InstallResult { var components []string status := KeybaseFuseStatus("", log) if status.InstallStatus == keybase1.InstallStatus_INSTALLED { components = []string{ ComponentNameCLI.String(), ComponentNameUpdater.String(), ComponentNameService.String(), ComponentNameKBFS.String(), ComponentNameHelper.String(), ComponentNameFuse.String(), ComponentNameMountDir.String(), ComponentNameRedirector.String(), ComponentNameKBFS.String(), ComponentNameKBNM.String(), } } else { components = []string{ ComponentNameCLI.String(), ComponentNameUpdater.String(), ComponentNameService.String(), ComponentNameKBFS.String(), ComponentNameKBNM.String(), } } // A force unmount is needed to change from one mountpoint to another // if the mount is in use after an upgrade, and install-auto is // invoked from the updater. forceUnmount := true return Install(context, binPath, sourcePath, components, forceUnmount, timeout, log) }
go
func InstallAuto(context Context, binPath string, sourcePath string, timeout time.Duration, log Log) keybase1.InstallResult { var components []string status := KeybaseFuseStatus("", log) if status.InstallStatus == keybase1.InstallStatus_INSTALLED { components = []string{ ComponentNameCLI.String(), ComponentNameUpdater.String(), ComponentNameService.String(), ComponentNameKBFS.String(), ComponentNameHelper.String(), ComponentNameFuse.String(), ComponentNameMountDir.String(), ComponentNameRedirector.String(), ComponentNameKBFS.String(), ComponentNameKBNM.String(), } } else { components = []string{ ComponentNameCLI.String(), ComponentNameUpdater.String(), ComponentNameService.String(), ComponentNameKBFS.String(), ComponentNameKBNM.String(), } } // A force unmount is needed to change from one mountpoint to another // if the mount is in use after an upgrade, and install-auto is // invoked from the updater. forceUnmount := true return Install(context, binPath, sourcePath, components, forceUnmount, timeout, log) }
[ "func", "InstallAuto", "(", "context", "Context", ",", "binPath", "string", ",", "sourcePath", "string", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "keybase1", ".", "InstallResult", "{", "var", "components", "[", "]", "string", "\n", "status", ":=", "KeybaseFuseStatus", "(", "\"", "\"", ",", "log", ")", "\n", "if", "status", ".", "InstallStatus", "==", "keybase1", ".", "InstallStatus_INSTALLED", "{", "components", "=", "[", "]", "string", "{", "ComponentNameCLI", ".", "String", "(", ")", ",", "ComponentNameUpdater", ".", "String", "(", ")", ",", "ComponentNameService", ".", "String", "(", ")", ",", "ComponentNameKBFS", ".", "String", "(", ")", ",", "ComponentNameHelper", ".", "String", "(", ")", ",", "ComponentNameFuse", ".", "String", "(", ")", ",", "ComponentNameMountDir", ".", "String", "(", ")", ",", "ComponentNameRedirector", ".", "String", "(", ")", ",", "ComponentNameKBFS", ".", "String", "(", ")", ",", "ComponentNameKBNM", ".", "String", "(", ")", ",", "}", "\n", "}", "else", "{", "components", "=", "[", "]", "string", "{", "ComponentNameCLI", ".", "String", "(", ")", ",", "ComponentNameUpdater", ".", "String", "(", ")", ",", "ComponentNameService", ".", "String", "(", ")", ",", "ComponentNameKBFS", ".", "String", "(", ")", ",", "ComponentNameKBNM", ".", "String", "(", ")", ",", "}", "\n", "}", "\n\n", "// A force unmount is needed to change from one mountpoint to another", "// if the mount is in use after an upgrade, and install-auto is", "// invoked from the updater.", "forceUnmount", ":=", "true", "\n", "return", "Install", "(", "context", ",", "binPath", ",", "sourcePath", ",", "components", ",", "forceUnmount", ",", "timeout", ",", "log", ")", "\n", "}" ]
// InstallAuto installs everything it can without asking for privileges or // extensions. If the user has already installed Fuse, we install everything.
[ "InstallAuto", "installs", "everything", "it", "can", "without", "asking", "for", "privileges", "or", "extensions", ".", "If", "the", "user", "has", "already", "installed", "Fuse", "we", "install", "everything", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L408-L439
160,027
keybase/client
go/install/install_darwin.go
InstallService
func InstallService(context Context, binPath string, force bool, timeout time.Duration, log Log) error { resolvedBinPath, err := chooseBinPath(binPath) if err != nil { return err } log.Debug("Using binPath: %s", resolvedBinPath) label := DefaultServiceLabel(context.GetRunMode()) service := launchd.NewService(label) plist, err := keybasePlist(context, resolvedBinPath, label, log) if err != nil { return err } UninstallKeybaseServices(context, log) log.Debug("Installing service (%s, timeout=%s)", label, timeout) if _, err := installKeybaseService(context, service, plist, timeout, log); err != nil { log.Errorf("Error installing Keybase service: %s", err) pid, err := fallbackStartProcessAndWaitForInfo(context, service, plist, context.GetServiceInfoPath(), timeout, log) if err != nil { return err } log.Debug("fallback keybase service started, pid=%d", pid) return nil } log.Debug("keybase service installed via launchd successfully") return nil }
go
func InstallService(context Context, binPath string, force bool, timeout time.Duration, log Log) error { resolvedBinPath, err := chooseBinPath(binPath) if err != nil { return err } log.Debug("Using binPath: %s", resolvedBinPath) label := DefaultServiceLabel(context.GetRunMode()) service := launchd.NewService(label) plist, err := keybasePlist(context, resolvedBinPath, label, log) if err != nil { return err } UninstallKeybaseServices(context, log) log.Debug("Installing service (%s, timeout=%s)", label, timeout) if _, err := installKeybaseService(context, service, plist, timeout, log); err != nil { log.Errorf("Error installing Keybase service: %s", err) pid, err := fallbackStartProcessAndWaitForInfo(context, service, plist, context.GetServiceInfoPath(), timeout, log) if err != nil { return err } log.Debug("fallback keybase service started, pid=%d", pid) return nil } log.Debug("keybase service installed via launchd successfully") return nil }
[ "func", "InstallService", "(", "context", "Context", ",", "binPath", "string", ",", "force", "bool", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "error", "{", "resolvedBinPath", ",", "err", ":=", "chooseBinPath", "(", "binPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "resolvedBinPath", ")", "\n\n", "label", ":=", "DefaultServiceLabel", "(", "context", ".", "GetRunMode", "(", ")", ")", "\n", "service", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n", "plist", ",", "err", ":=", "keybasePlist", "(", "context", ",", "resolvedBinPath", ",", "label", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "UninstallKeybaseServices", "(", "context", ",", "log", ")", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "label", ",", "timeout", ")", "\n", "if", "_", ",", "err", ":=", "installKeybaseService", "(", "context", ",", "service", ",", "plist", ",", "timeout", ",", "log", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "pid", ",", "err", ":=", "fallbackStartProcessAndWaitForInfo", "(", "context", ",", "service", ",", "plist", ",", "context", ".", "GetServiceInfoPath", "(", ")", ",", "timeout", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "pid", ")", "\n", "return", "nil", "\n", "}", "\n", "log", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// InstallService installs the launchd service
[ "InstallService", "installs", "the", "launchd", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L691-L717
160,028
keybase/client
go/install/install_darwin.go
InstallKBFS
func InstallKBFS(context Context, binPath string, force bool, skipMountIfNotAvailable bool, timeout time.Duration, log Log) error { runMode := context.GetRunMode() label := DefaultKBFSLabel(runMode) kbfsService := launchd.NewService(label) kbfsBinPath, err := KBFSBinPath(runMode, binPath) if err != nil { return err } // Unmount any existing KBFS directory for the user. mountDir, err := context.GetMountDir() if err != nil { return err } skipMount := false _, err = os.Stat(mountDir) if err != nil { if skipMountIfNotAvailable { skipMount = true } else { return err } } plist, err := kbfsPlist(context, kbfsBinPath, label, mountDir, skipMount, log) if err != nil { return err } UninstallKBFSServices(context, log) log.Debug("Installing KBFS (%s, timeout=%s)", label, timeout) if _, err := installKBFSService(context, kbfsService, plist, timeout, log); err != nil { log.Errorf("error installing KBFS: %s", err) pid, err := fallbackStartProcessAndWaitForInfo(context, kbfsService, plist, context.GetKBFSInfoPath(), timeout, log) if err != nil { return err } log.Debug("fallback KBFS service started, pid=%d", pid) return nil } log.Debug("KBFS installed via launchd successfully") return nil }
go
func InstallKBFS(context Context, binPath string, force bool, skipMountIfNotAvailable bool, timeout time.Duration, log Log) error { runMode := context.GetRunMode() label := DefaultKBFSLabel(runMode) kbfsService := launchd.NewService(label) kbfsBinPath, err := KBFSBinPath(runMode, binPath) if err != nil { return err } // Unmount any existing KBFS directory for the user. mountDir, err := context.GetMountDir() if err != nil { return err } skipMount := false _, err = os.Stat(mountDir) if err != nil { if skipMountIfNotAvailable { skipMount = true } else { return err } } plist, err := kbfsPlist(context, kbfsBinPath, label, mountDir, skipMount, log) if err != nil { return err } UninstallKBFSServices(context, log) log.Debug("Installing KBFS (%s, timeout=%s)", label, timeout) if _, err := installKBFSService(context, kbfsService, plist, timeout, log); err != nil { log.Errorf("error installing KBFS: %s", err) pid, err := fallbackStartProcessAndWaitForInfo(context, kbfsService, plist, context.GetKBFSInfoPath(), timeout, log) if err != nil { return err } log.Debug("fallback KBFS service started, pid=%d", pid) return nil } log.Debug("KBFS installed via launchd successfully") return nil }
[ "func", "InstallKBFS", "(", "context", "Context", ",", "binPath", "string", ",", "force", "bool", ",", "skipMountIfNotAvailable", "bool", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "error", "{", "runMode", ":=", "context", ".", "GetRunMode", "(", ")", "\n", "label", ":=", "DefaultKBFSLabel", "(", "runMode", ")", "\n", "kbfsService", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n", "kbfsBinPath", ",", "err", ":=", "KBFSBinPath", "(", "runMode", ",", "binPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// Unmount any existing KBFS directory for the user.", "mountDir", ",", "err", ":=", "context", ".", "GetMountDir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "skipMount", ":=", "false", "\n", "_", ",", "err", "=", "os", ".", "Stat", "(", "mountDir", ")", "\n", "if", "err", "!=", "nil", "{", "if", "skipMountIfNotAvailable", "{", "skipMount", "=", "true", "\n", "}", "else", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "plist", ",", "err", ":=", "kbfsPlist", "(", "context", ",", "kbfsBinPath", ",", "label", ",", "mountDir", ",", "skipMount", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "UninstallKBFSServices", "(", "context", ",", "log", ")", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "label", ",", "timeout", ")", "\n", "if", "_", ",", "err", ":=", "installKBFSService", "(", "context", ",", "kbfsService", ",", "plist", ",", "timeout", ",", "log", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "pid", ",", "err", ":=", "fallbackStartProcessAndWaitForInfo", "(", "context", ",", "kbfsService", ",", "plist", ",", "context", ".", "GetKBFSInfoPath", "(", ")", ",", "timeout", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "pid", ")", "\n", "return", "nil", "\n", "}", "\n\n", "log", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// InstallKBFS installs the KBFS launchd service
[ "InstallKBFS", "installs", "the", "KBFS", "launchd", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L720-L763
160,029
keybase/client
go/install/install_darwin.go
InstallKBNM
func InstallKBNM(context Context, binPath string, log Log) error { // Find path of the keybase binary keybasePath, err := chooseBinPath(binPath) if err != nil { return err } // kbnm binary is next to the keybase binary, same dir hostPath := filepath.Join(filepath.Dir(keybasePath), "kbnm") log.Info("Installing KBNM NativeMessaging whitelists for binary: %s", hostPath) return kbnminstaller.InstallKBNM(hostPath) }
go
func InstallKBNM(context Context, binPath string, log Log) error { // Find path of the keybase binary keybasePath, err := chooseBinPath(binPath) if err != nil { return err } // kbnm binary is next to the keybase binary, same dir hostPath := filepath.Join(filepath.Dir(keybasePath), "kbnm") log.Info("Installing KBNM NativeMessaging whitelists for binary: %s", hostPath) return kbnminstaller.InstallKBNM(hostPath) }
[ "func", "InstallKBNM", "(", "context", "Context", ",", "binPath", "string", ",", "log", "Log", ")", "error", "{", "// Find path of the keybase binary", "keybasePath", ",", "err", ":=", "chooseBinPath", "(", "binPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// kbnm binary is next to the keybase binary, same dir", "hostPath", ":=", "filepath", ".", "Join", "(", "filepath", ".", "Dir", "(", "keybasePath", ")", ",", "\"", "\"", ")", "\n\n", "log", ".", "Info", "(", "\"", "\"", ",", "hostPath", ")", "\n", "return", "kbnminstaller", ".", "InstallKBNM", "(", "hostPath", ")", "\n", "}" ]
// InstallKBNM installs the Keybase NativeMessaging whitelist
[ "InstallKBNM", "installs", "the", "Keybase", "NativeMessaging", "whitelist" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L766-L777
160,030
keybase/client
go/install/install_darwin.go
UninstallKBFS
func UninstallKBFS(context Context, mountDir string, forceUnmount bool, log Log) error { err := UninstallKBFSServices(context, log) if err != nil { log.Warning("Couldn't stop KBFS: %+v", err) // Continue despite the error, since the uninstall doesn't // seem to be resilient against the "fallback" PID getting out // of sync with the true KBFS PID. TODO: fix the fallback PID // logic? } return unmount(mountDir, forceUnmount, log) }
go
func UninstallKBFS(context Context, mountDir string, forceUnmount bool, log Log) error { err := UninstallKBFSServices(context, log) if err != nil { log.Warning("Couldn't stop KBFS: %+v", err) // Continue despite the error, since the uninstall doesn't // seem to be resilient against the "fallback" PID getting out // of sync with the true KBFS PID. TODO: fix the fallback PID // logic? } return unmount(mountDir, forceUnmount, log) }
[ "func", "UninstallKBFS", "(", "context", "Context", ",", "mountDir", "string", ",", "forceUnmount", "bool", ",", "log", "Log", ")", "error", "{", "err", ":=", "UninstallKBFSServices", "(", "context", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Warning", "(", "\"", "\"", ",", "err", ")", "\n", "// Continue despite the error, since the uninstall doesn't", "// seem to be resilient against the \"fallback\" PID getting out", "// of sync with the true KBFS PID. TODO: fix the fallback PID", "// logic?", "}", "\n\n", "return", "unmount", "(", "mountDir", ",", "forceUnmount", ",", "log", ")", "\n", "}" ]
// UninstallKBFS uninstalls all KBFS services, unmounts and optionally removes the mount directory
[ "UninstallKBFS", "uninstalls", "all", "KBFS", "services", "unmounts", "and", "optionally", "removes", "the", "mount", "directory" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L936-L947
160,031
keybase/client
go/install/install_darwin.go
AutoInstallWithStatus
func AutoInstallWithStatus(context Context, binPath string, force bool, timeout time.Duration, log Log) keybase1.InstallResult { _, res, err := autoInstall(context, binPath, force, timeout, log) if err != nil { return keybase1.InstallResult{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCInstallError, err.Error())} } return newInstallResult(res) }
go
func AutoInstallWithStatus(context Context, binPath string, force bool, timeout time.Duration, log Log) keybase1.InstallResult { _, res, err := autoInstall(context, binPath, force, timeout, log) if err != nil { return keybase1.InstallResult{Status: keybase1.StatusFromCode(keybase1.StatusCode_SCInstallError, err.Error())} } return newInstallResult(res) }
[ "func", "AutoInstallWithStatus", "(", "context", "Context", ",", "binPath", "string", ",", "force", "bool", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "keybase1", ".", "InstallResult", "{", "_", ",", "res", ",", "err", ":=", "autoInstall", "(", "context", ",", "binPath", ",", "force", ",", "timeout", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "keybase1", ".", "InstallResult", "{", "Status", ":", "keybase1", ".", "StatusFromCode", "(", "keybase1", ".", "StatusCode_SCInstallError", ",", "err", ".", "Error", "(", ")", ")", "}", "\n", "}", "\n", "return", "newInstallResult", "(", "res", ")", "\n", "}" ]
// AutoInstallWithStatus runs the auto install and returns a result
[ "AutoInstallWithStatus", "runs", "the", "auto", "install", "and", "returns", "a", "result" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L950-L956
160,032
keybase/client
go/install/install_darwin.go
AutoInstall
func AutoInstall(context Context, binPath string, force bool, timeout time.Duration, log Log) (newProc bool, err error) { if context.GetRunMode() != libkb.ProductionRunMode { return false, fmt.Errorf("Auto install is only supported in production") } newProc, _, err = autoInstall(context, binPath, force, timeout, log) return }
go
func AutoInstall(context Context, binPath string, force bool, timeout time.Duration, log Log) (newProc bool, err error) { if context.GetRunMode() != libkb.ProductionRunMode { return false, fmt.Errorf("Auto install is only supported in production") } newProc, _, err = autoInstall(context, binPath, force, timeout, log) return }
[ "func", "AutoInstall", "(", "context", "Context", ",", "binPath", "string", ",", "force", "bool", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "(", "newProc", "bool", ",", "err", "error", ")", "{", "if", "context", ".", "GetRunMode", "(", ")", "!=", "libkb", ".", "ProductionRunMode", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "newProc", ",", "_", ",", "err", "=", "autoInstall", "(", "context", ",", "binPath", ",", "force", ",", "timeout", ",", "log", ")", "\n", "return", "\n", "}" ]
// AutoInstall runs the auto install
[ "AutoInstall", "runs", "the", "auto", "install" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L959-L966
160,033
keybase/client
go/install/install_darwin.go
isPathInDMG
func isPathInDMG(p string) (inDMG bool, bundlePath string, err error) { var stat syscall.Statfs_t err = syscall.Statfs(p, &stat) if err != nil { return } // mntRootFS identifies the root filesystem (http://www.opensource.apple.com/source/xnu/xnu-344.26/bsd/sys/mount.h) const mntRootFS = 0x00004000 if (stat.Flags & mntRootFS) != 0 { // We're on the root filesystem so we're not in a DMG return } bundlePath = bundleDirForPath(p) if bundlePath != "" { // Look for Applications symlink in the same folder as Keybase.app, and if // we find it, we're really likely to be in a mounted dmg appLink := filepath.Join(filepath.Dir(bundlePath), "Applications") fi, ferr := os.Lstat(appLink) if os.IsNotExist(ferr) { return } isLink := (fi.Mode()&os.ModeSymlink != 0) if isLink { inDMG = true return } } return }
go
func isPathInDMG(p string) (inDMG bool, bundlePath string, err error) { var stat syscall.Statfs_t err = syscall.Statfs(p, &stat) if err != nil { return } // mntRootFS identifies the root filesystem (http://www.opensource.apple.com/source/xnu/xnu-344.26/bsd/sys/mount.h) const mntRootFS = 0x00004000 if (stat.Flags & mntRootFS) != 0 { // We're on the root filesystem so we're not in a DMG return } bundlePath = bundleDirForPath(p) if bundlePath != "" { // Look for Applications symlink in the same folder as Keybase.app, and if // we find it, we're really likely to be in a mounted dmg appLink := filepath.Join(filepath.Dir(bundlePath), "Applications") fi, ferr := os.Lstat(appLink) if os.IsNotExist(ferr) { return } isLink := (fi.Mode()&os.ModeSymlink != 0) if isLink { inDMG = true return } } return }
[ "func", "isPathInDMG", "(", "p", "string", ")", "(", "inDMG", "bool", ",", "bundlePath", "string", ",", "err", "error", ")", "{", "var", "stat", "syscall", ".", "Statfs_t", "\n", "err", "=", "syscall", ".", "Statfs", "(", "p", ",", "&", "stat", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// mntRootFS identifies the root filesystem (http://www.opensource.apple.com/source/xnu/xnu-344.26/bsd/sys/mount.h)", "const", "mntRootFS", "=", "0x00004000", "\n\n", "if", "(", "stat", ".", "Flags", "&", "mntRootFS", ")", "!=", "0", "{", "// We're on the root filesystem so we're not in a DMG", "return", "\n", "}", "\n\n", "bundlePath", "=", "bundleDirForPath", "(", "p", ")", "\n", "if", "bundlePath", "!=", "\"", "\"", "{", "// Look for Applications symlink in the same folder as Keybase.app, and if", "// we find it, we're really likely to be in a mounted dmg", "appLink", ":=", "filepath", ".", "Join", "(", "filepath", ".", "Dir", "(", "bundlePath", ")", ",", "\"", "\"", ")", "\n", "fi", ",", "ferr", ":=", "os", ".", "Lstat", "(", "appLink", ")", "\n", "if", "os", ".", "IsNotExist", "(", "ferr", ")", "{", "return", "\n", "}", "\n", "isLink", ":=", "(", "fi", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "!=", "0", ")", "\n", "if", "isLink", "{", "inDMG", "=", "true", "\n", "return", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// isPathInDMG errors if the path is inside dmg
[ "isPathInDMG", "errors", "if", "the", "path", "is", "inside", "dmg" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L1024-L1056
160,034
keybase/client
go/install/install_darwin.go
OSVersion
func OSVersion() (semver.Version, error) { out, err := exec.Command("sw_vers", "-productVersion").Output() if err != nil { return semver.Version{}, err } swver := strings.TrimSpace(string(out)) // The version might not be semver compliant for beta macOS (e.g. "10.12") if strings.Count(swver, ".") == 1 { swver = swver + ".0" } return semver.Make(swver) }
go
func OSVersion() (semver.Version, error) { out, err := exec.Command("sw_vers", "-productVersion").Output() if err != nil { return semver.Version{}, err } swver := strings.TrimSpace(string(out)) // The version might not be semver compliant for beta macOS (e.g. "10.12") if strings.Count(swver, ".") == 1 { swver = swver + ".0" } return semver.Make(swver) }
[ "func", "OSVersion", "(", ")", "(", "semver", ".", "Version", ",", "error", ")", "{", "out", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ")", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "semver", ".", "Version", "{", "}", ",", "err", "\n", "}", "\n", "swver", ":=", "strings", ".", "TrimSpace", "(", "string", "(", "out", ")", ")", "\n", "// The version might not be semver compliant for beta macOS (e.g. \"10.12\")", "if", "strings", ".", "Count", "(", "swver", ",", "\"", "\"", ")", "==", "1", "{", "swver", "=", "swver", "+", "\"", "\"", "\n", "}", "\n", "return", "semver", ".", "Make", "(", "swver", ")", "\n", "}" ]
// OSVersion returns the OS version
[ "OSVersion", "returns", "the", "OS", "version" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L1144-L1155
160,035
keybase/client
go/install/install_darwin.go
InstallUpdater
func InstallUpdater(context Context, keybaseBinPath string, force bool, timeout time.Duration, log Log) error { if context.GetRunMode() != libkb.ProductionRunMode { return fmt.Errorf("Updater not supported in this run mode") } keybaseBinPath, err := chooseBinPath(keybaseBinPath) if err != nil { return err } updaterBinPath := filepath.Join(filepath.Dir(keybaseBinPath), "updater") if err != nil { return err } log.Debug("Using updater path: %s", updaterBinPath) label := DefaultUpdaterLabel(context.GetRunMode()) service := launchd.NewService(label) plist, err := updaterPlist(context, label, updaterBinPath, keybaseBinPath, log) if err != nil { return err } UninstallUpdaterService(context, log) log.Debug("Installing updater service (%s, timeout=%s)", label, timeout) if _, err := installUpdaterService(context, service, plist, timeout, log); err != nil { log.Errorf("Error installing updater service: %s", err) _, err = fallbackStartProcess(context, service, plist, log) return err } return nil }
go
func InstallUpdater(context Context, keybaseBinPath string, force bool, timeout time.Duration, log Log) error { if context.GetRunMode() != libkb.ProductionRunMode { return fmt.Errorf("Updater not supported in this run mode") } keybaseBinPath, err := chooseBinPath(keybaseBinPath) if err != nil { return err } updaterBinPath := filepath.Join(filepath.Dir(keybaseBinPath), "updater") if err != nil { return err } log.Debug("Using updater path: %s", updaterBinPath) label := DefaultUpdaterLabel(context.GetRunMode()) service := launchd.NewService(label) plist, err := updaterPlist(context, label, updaterBinPath, keybaseBinPath, log) if err != nil { return err } UninstallUpdaterService(context, log) log.Debug("Installing updater service (%s, timeout=%s)", label, timeout) if _, err := installUpdaterService(context, service, plist, timeout, log); err != nil { log.Errorf("Error installing updater service: %s", err) _, err = fallbackStartProcess(context, service, plist, log) return err } return nil }
[ "func", "InstallUpdater", "(", "context", "Context", ",", "keybaseBinPath", "string", ",", "force", "bool", ",", "timeout", "time", ".", "Duration", ",", "log", "Log", ")", "error", "{", "if", "context", ".", "GetRunMode", "(", ")", "!=", "libkb", ".", "ProductionRunMode", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "keybaseBinPath", ",", "err", ":=", "chooseBinPath", "(", "keybaseBinPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "updaterBinPath", ":=", "filepath", ".", "Join", "(", "filepath", ".", "Dir", "(", "keybaseBinPath", ")", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "updaterBinPath", ")", "\n\n", "label", ":=", "DefaultUpdaterLabel", "(", "context", ".", "GetRunMode", "(", ")", ")", "\n", "service", ":=", "launchd", ".", "NewService", "(", "label", ")", "\n", "plist", ",", "err", ":=", "updaterPlist", "(", "context", ",", "label", ",", "updaterBinPath", ",", "keybaseBinPath", ",", "log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "UninstallUpdaterService", "(", "context", ",", "log", ")", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "label", ",", "timeout", ")", "\n", "if", "_", ",", "err", ":=", "installUpdaterService", "(", "context", ",", "service", ",", "plist", ",", "timeout", ",", "log", ")", ";", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "_", ",", "err", "=", "fallbackStartProcess", "(", "context", ",", "service", ",", "plist", ",", "log", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// InstallUpdater installs the updater launchd service
[ "InstallUpdater", "installs", "the", "updater", "launchd", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L1158-L1187
160,036
keybase/client
go/install/install_darwin.go
UninstallUpdaterService
func UninstallUpdaterService(context Context, log Log) error { runMode := context.GetRunMode() pidFile := filepath.Join(context.GetCacheDir(), "updater.pid") err0 := fallbackKillProcess(context, log, DefaultUpdaterLabel(runMode), "", pidFile) err1 := launchd.Uninstall(DefaultUpdaterLabel(runMode), defaultLaunchdWait, log) return libkb.CombineErrors(err0, err1) }
go
func UninstallUpdaterService(context Context, log Log) error { runMode := context.GetRunMode() pidFile := filepath.Join(context.GetCacheDir(), "updater.pid") err0 := fallbackKillProcess(context, log, DefaultUpdaterLabel(runMode), "", pidFile) err1 := launchd.Uninstall(DefaultUpdaterLabel(runMode), defaultLaunchdWait, log) return libkb.CombineErrors(err0, err1) }
[ "func", "UninstallUpdaterService", "(", "context", "Context", ",", "log", "Log", ")", "error", "{", "runMode", ":=", "context", ".", "GetRunMode", "(", ")", "\n", "pidFile", ":=", "filepath", ".", "Join", "(", "context", ".", "GetCacheDir", "(", ")", ",", "\"", "\"", ")", "\n", "err0", ":=", "fallbackKillProcess", "(", "context", ",", "log", ",", "DefaultUpdaterLabel", "(", "runMode", ")", ",", "\"", "\"", ",", "pidFile", ")", "\n", "err1", ":=", "launchd", ".", "Uninstall", "(", "DefaultUpdaterLabel", "(", "runMode", ")", ",", "defaultLaunchdWait", ",", "log", ")", "\n", "return", "libkb", ".", "CombineErrors", "(", "err0", ",", "err1", ")", "\n", "}" ]
// UninstallUpdaterService removes updater launchd service
[ "UninstallUpdaterService", "removes", "updater", "launchd", "service" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L1213-L1219
160,037
keybase/client
go/install/install_darwin.go
RunApp
func RunApp(context Context, log Log) error { appPath, err := libnativeinstaller.AppBundleForPath() if err != nil { return err } ver, err := OSVersion() if err != nil { log.Errorf("Error trying to determine OS version: %s", err) return nil } if ver.LT(semver.MustParse("10.0.0")) { return fmt.Errorf("App isn't supported on this OS version: %s", ver) } log.Info("Opening %s", appPath) // If app is already open this is a no-op, the -g option will cause to open // in background. out, err := exec.Command("/usr/bin/open", "-g", appPath).Output() if err != nil { return fmt.Errorf("Error trying to open %s: %s; %s", appPath, err, out) } return nil }
go
func RunApp(context Context, log Log) error { appPath, err := libnativeinstaller.AppBundleForPath() if err != nil { return err } ver, err := OSVersion() if err != nil { log.Errorf("Error trying to determine OS version: %s", err) return nil } if ver.LT(semver.MustParse("10.0.0")) { return fmt.Errorf("App isn't supported on this OS version: %s", ver) } log.Info("Opening %s", appPath) // If app is already open this is a no-op, the -g option will cause to open // in background. out, err := exec.Command("/usr/bin/open", "-g", appPath).Output() if err != nil { return fmt.Errorf("Error trying to open %s: %s; %s", appPath, err, out) } return nil }
[ "func", "RunApp", "(", "context", "Context", ",", "log", "Log", ")", "error", "{", "appPath", ",", "err", ":=", "libnativeinstaller", ".", "AppBundleForPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "ver", ",", "err", ":=", "OSVersion", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "ver", ".", "LT", "(", "semver", ".", "MustParse", "(", "\"", "\"", ")", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ver", ")", "\n", "}", "\n\n", "log", ".", "Info", "(", "\"", "\"", ",", "appPath", ")", "\n", "// If app is already open this is a no-op, the -g option will cause to open", "// in background.", "out", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "appPath", ")", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "appPath", ",", "err", ",", "out", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RunApp starts the app
[ "RunApp", "starts", "the", "app" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/install_darwin.go#L1231-L1253
160,038
keybase/client
go/libkb/sign.go
SimpleSign
func SimpleSign(payload []byte, key PGPKeyBundle) (out string, id keybase1.SigID, err error) { var outb bytes.Buffer var in io.WriteCloser var h HashSummer if !key.HasSecretKey() { err = NoSecretKeyError{} return } if in, h, err = ArmoredAttachedSign(NopWriteCloser{&outb}, *key.Entity, nil, nil); err != nil { return } if _, err = in.Write(payload); err != nil { return } if err = in.Close(); err != nil { return } out = outb.String() if id, err = keybase1.SigIDFromSlice(h()); err != nil { return } return }
go
func SimpleSign(payload []byte, key PGPKeyBundle) (out string, id keybase1.SigID, err error) { var outb bytes.Buffer var in io.WriteCloser var h HashSummer if !key.HasSecretKey() { err = NoSecretKeyError{} return } if in, h, err = ArmoredAttachedSign(NopWriteCloser{&outb}, *key.Entity, nil, nil); err != nil { return } if _, err = in.Write(payload); err != nil { return } if err = in.Close(); err != nil { return } out = outb.String() if id, err = keybase1.SigIDFromSlice(h()); err != nil { return } return }
[ "func", "SimpleSign", "(", "payload", "[", "]", "byte", ",", "key", "PGPKeyBundle", ")", "(", "out", "string", ",", "id", "keybase1", ".", "SigID", ",", "err", "error", ")", "{", "var", "outb", "bytes", ".", "Buffer", "\n", "var", "in", "io", ".", "WriteCloser", "\n", "var", "h", "HashSummer", "\n", "if", "!", "key", ".", "HasSecretKey", "(", ")", "{", "err", "=", "NoSecretKeyError", "{", "}", "\n", "return", "\n", "}", "\n", "if", "in", ",", "h", ",", "err", "=", "ArmoredAttachedSign", "(", "NopWriteCloser", "{", "&", "outb", "}", ",", "*", "key", ".", "Entity", ",", "nil", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "_", ",", "err", "=", "in", ".", "Write", "(", "payload", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "err", "=", "in", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "out", "=", "outb", ".", "String", "(", ")", "\n", "if", "id", ",", "err", "=", "keybase1", ".", "SigIDFromSlice", "(", "h", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "\n", "}" ]
// SimpleSign signs the given data stream, outputs an armored string which is // the attached signature of the input data
[ "SimpleSign", "signs", "the", "given", "data", "stream", "outputs", "an", "armored", "string", "which", "is", "the", "attached", "signature", "of", "the", "input", "data" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/sign.go#L20-L42
160,039
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MakeRandomTLFCryptKeyServerHalf
func MakeRandomTLFCryptKeyServerHalf() ( serverHalf TLFCryptKeyServerHalf, err error) { var data [32]byte err = RandRead(data[:]) if err != nil { return TLFCryptKeyServerHalf{}, err } serverHalf = MakeTLFCryptKeyServerHalf(data) return serverHalf, nil }
go
func MakeRandomTLFCryptKeyServerHalf() ( serverHalf TLFCryptKeyServerHalf, err error) { var data [32]byte err = RandRead(data[:]) if err != nil { return TLFCryptKeyServerHalf{}, err } serverHalf = MakeTLFCryptKeyServerHalf(data) return serverHalf, nil }
[ "func", "MakeRandomTLFCryptKeyServerHalf", "(", ")", "(", "serverHalf", "TLFCryptKeyServerHalf", ",", "err", "error", ")", "{", "var", "data", "[", "32", "]", "byte", "\n", "err", "=", "RandRead", "(", "data", "[", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "TLFCryptKeyServerHalf", "{", "}", ",", "err", "\n", "}", "\n", "serverHalf", "=", "MakeTLFCryptKeyServerHalf", "(", "data", ")", "\n", "return", "serverHalf", ",", "nil", "\n", "}" ]
// MakeRandomTLFCryptKeyServerHalf generates the server-side of a // top-level folder crypt key.
[ "MakeRandomTLFCryptKeyServerHalf", "generates", "the", "server", "-", "side", "of", "a", "top", "-", "level", "folder", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L404-L413
160,040
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MakeTLFCryptKeyServerHalfID
func MakeTLFCryptKeyServerHalfID( user keybase1.UID, devicePubKey CryptPublicKey, serverHalf TLFCryptKeyServerHalf) ( TLFCryptKeyServerHalfID, error) { key, err := serverHalf.MarshalBinary() if err != nil { return TLFCryptKeyServerHalfID{}, err } data := append(user.ToBytes(), devicePubKey.KID().ToBytes()...) hmac, err := kbfshash.DefaultHMAC(key, data) if err != nil { return TLFCryptKeyServerHalfID{}, err } return TLFCryptKeyServerHalfID{ ID: hmac, }, nil }
go
func MakeTLFCryptKeyServerHalfID( user keybase1.UID, devicePubKey CryptPublicKey, serverHalf TLFCryptKeyServerHalf) ( TLFCryptKeyServerHalfID, error) { key, err := serverHalf.MarshalBinary() if err != nil { return TLFCryptKeyServerHalfID{}, err } data := append(user.ToBytes(), devicePubKey.KID().ToBytes()...) hmac, err := kbfshash.DefaultHMAC(key, data) if err != nil { return TLFCryptKeyServerHalfID{}, err } return TLFCryptKeyServerHalfID{ ID: hmac, }, nil }
[ "func", "MakeTLFCryptKeyServerHalfID", "(", "user", "keybase1", ".", "UID", ",", "devicePubKey", "CryptPublicKey", ",", "serverHalf", "TLFCryptKeyServerHalf", ")", "(", "TLFCryptKeyServerHalfID", ",", "error", ")", "{", "key", ",", "err", ":=", "serverHalf", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "TLFCryptKeyServerHalfID", "{", "}", ",", "err", "\n", "}", "\n", "data", ":=", "append", "(", "user", ".", "ToBytes", "(", ")", ",", "devicePubKey", ".", "KID", "(", ")", ".", "ToBytes", "(", ")", "...", ")", "\n", "hmac", ",", "err", ":=", "kbfshash", ".", "DefaultHMAC", "(", "key", ",", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "TLFCryptKeyServerHalfID", "{", "}", ",", "err", "\n", "}", "\n", "return", "TLFCryptKeyServerHalfID", "{", "ID", ":", "hmac", ",", "}", ",", "nil", "\n", "}" ]
// MakeTLFCryptKeyServerHalfID creates a unique ID for this particular // TLFCryptKeyServerHalf.
[ "MakeTLFCryptKeyServerHalfID", "creates", "a", "unique", "ID", "for", "this", "particular", "TLFCryptKeyServerHalf", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L427-L443
160,041
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
VerifyTLFCryptKeyServerHalfID
func VerifyTLFCryptKeyServerHalfID( serverHalfID TLFCryptKeyServerHalfID, user keybase1.UID, devicePubKey CryptPublicKey, serverHalf TLFCryptKeyServerHalf) error { key, err := serverHalf.MarshalBinary() if err != nil { return err } data := append(user.ToBytes(), devicePubKey.KID().ToBytes()...) return serverHalfID.ID.Verify(key, data) }
go
func VerifyTLFCryptKeyServerHalfID( serverHalfID TLFCryptKeyServerHalfID, user keybase1.UID, devicePubKey CryptPublicKey, serverHalf TLFCryptKeyServerHalf) error { key, err := serverHalf.MarshalBinary() if err != nil { return err } data := append(user.ToBytes(), devicePubKey.KID().ToBytes()...) return serverHalfID.ID.Verify(key, data) }
[ "func", "VerifyTLFCryptKeyServerHalfID", "(", "serverHalfID", "TLFCryptKeyServerHalfID", ",", "user", "keybase1", ".", "UID", ",", "devicePubKey", "CryptPublicKey", ",", "serverHalf", "TLFCryptKeyServerHalf", ")", "error", "{", "key", ",", "err", ":=", "serverHalf", ".", "MarshalBinary", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "data", ":=", "append", "(", "user", ".", "ToBytes", "(", ")", ",", "devicePubKey", ".", "KID", "(", ")", ".", "ToBytes", "(", ")", "...", ")", "\n", "return", "serverHalfID", ".", "ID", ".", "Verify", "(", "key", ",", "data", ")", "\n", "}" ]
// VerifyTLFCryptKeyServerHalfID verifies the ID is the proper HMAC result.
[ "VerifyTLFCryptKeyServerHalfID", "verifies", "the", "ID", "is", "the", "proper", "HMAC", "result", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L446-L456
160,042
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
DecryptTLFCryptKeyClientHalf
func DecryptTLFCryptKeyClientHalf( privateKey CryptPrivateKey, publicKey TLFEphemeralPublicKey, encryptedClientHalf EncryptedTLFCryptKeyClientHalf) ( TLFCryptKeyClientHalf, error) { nonce, err := prepareTLFCryptKeyClientHalf(encryptedClientHalf) if err != nil { return TLFCryptKeyClientHalf{}, err } publicKeyData := publicKey.Data() privateKeyData := privateKey.Data() decryptedData, ok := box.Open(nil, encryptedClientHalf.EncryptedData, &nonce, &publicKeyData, &privateKeyData) if !ok { return TLFCryptKeyClientHalf{}, errors.WithStack(libkb.DecryptionError{Cause: errors.New( "Can't unbox TLF crypt key client half")}) } var clientHalfData [32]byte if len(decryptedData) != len(clientHalfData) { return TLFCryptKeyClientHalf{}, errors.WithStack(libkb.DecryptionError{Cause: errors.New( "TLF crypt key client half has wrong data length")}) } copy(clientHalfData[:], decryptedData) return MakeTLFCryptKeyClientHalf(clientHalfData), nil }
go
func DecryptTLFCryptKeyClientHalf( privateKey CryptPrivateKey, publicKey TLFEphemeralPublicKey, encryptedClientHalf EncryptedTLFCryptKeyClientHalf) ( TLFCryptKeyClientHalf, error) { nonce, err := prepareTLFCryptKeyClientHalf(encryptedClientHalf) if err != nil { return TLFCryptKeyClientHalf{}, err } publicKeyData := publicKey.Data() privateKeyData := privateKey.Data() decryptedData, ok := box.Open(nil, encryptedClientHalf.EncryptedData, &nonce, &publicKeyData, &privateKeyData) if !ok { return TLFCryptKeyClientHalf{}, errors.WithStack(libkb.DecryptionError{Cause: errors.New( "Can't unbox TLF crypt key client half")}) } var clientHalfData [32]byte if len(decryptedData) != len(clientHalfData) { return TLFCryptKeyClientHalf{}, errors.WithStack(libkb.DecryptionError{Cause: errors.New( "TLF crypt key client half has wrong data length")}) } copy(clientHalfData[:], decryptedData) return MakeTLFCryptKeyClientHalf(clientHalfData), nil }
[ "func", "DecryptTLFCryptKeyClientHalf", "(", "privateKey", "CryptPrivateKey", ",", "publicKey", "TLFEphemeralPublicKey", ",", "encryptedClientHalf", "EncryptedTLFCryptKeyClientHalf", ")", "(", "TLFCryptKeyClientHalf", ",", "error", ")", "{", "nonce", ",", "err", ":=", "prepareTLFCryptKeyClientHalf", "(", "encryptedClientHalf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "TLFCryptKeyClientHalf", "{", "}", ",", "err", "\n", "}", "\n\n", "publicKeyData", ":=", "publicKey", ".", "Data", "(", ")", "\n", "privateKeyData", ":=", "privateKey", ".", "Data", "(", ")", "\n", "decryptedData", ",", "ok", ":=", "box", ".", "Open", "(", "nil", ",", "encryptedClientHalf", ".", "EncryptedData", ",", "&", "nonce", ",", "&", "publicKeyData", ",", "&", "privateKeyData", ")", "\n", "if", "!", "ok", "{", "return", "TLFCryptKeyClientHalf", "{", "}", ",", "errors", ".", "WithStack", "(", "libkb", ".", "DecryptionError", "{", "Cause", ":", "errors", ".", "New", "(", "\"", "\"", ")", "}", ")", "\n", "}", "\n\n", "var", "clientHalfData", "[", "32", "]", "byte", "\n", "if", "len", "(", "decryptedData", ")", "!=", "len", "(", "clientHalfData", ")", "{", "return", "TLFCryptKeyClientHalf", "{", "}", ",", "errors", ".", "WithStack", "(", "libkb", ".", "DecryptionError", "{", "Cause", ":", "errors", ".", "New", "(", "\"", "\"", ")", "}", ")", "\n", "}", "\n\n", "copy", "(", "clientHalfData", "[", ":", "]", ",", "decryptedData", ")", "\n", "return", "MakeTLFCryptKeyClientHalf", "(", "clientHalfData", ")", ",", "nil", "\n", "}" ]
// DecryptTLFCryptKeyClientHalf decrypts a // TLFCryptKeyClientHalf using the given device private key // and the TLF's ephemeral public key.
[ "DecryptTLFCryptKeyClientHalf", "decrypts", "a", "TLFCryptKeyClientHalf", "using", "the", "given", "device", "private", "key", "and", "the", "TLF", "s", "ephemeral", "public", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L510-L538
160,043
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MakeRandomTLFCryptKey
func MakeRandomTLFCryptKey() (TLFCryptKey, error) { var data [32]byte err := RandRead(data[:]) if err != nil { return TLFCryptKey{}, err } return MakeTLFCryptKey(data), nil }
go
func MakeRandomTLFCryptKey() (TLFCryptKey, error) { var data [32]byte err := RandRead(data[:]) if err != nil { return TLFCryptKey{}, err } return MakeTLFCryptKey(data), nil }
[ "func", "MakeRandomTLFCryptKey", "(", ")", "(", "TLFCryptKey", ",", "error", ")", "{", "var", "data", "[", "32", "]", "byte", "\n", "err", ":=", "RandRead", "(", "data", "[", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "TLFCryptKey", "{", "}", ",", "err", "\n", "}", "\n", "return", "MakeTLFCryptKey", "(", "data", ")", ",", "nil", "\n", "}" ]
// MakeRandomTLFCryptKey returns a random top-level folder crypt key.
[ "MakeRandomTLFCryptKey", "returns", "a", "random", "top", "-", "level", "folder", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L562-L569
160,044
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MakeRandomBlockCryptKeyServerHalf
func MakeRandomBlockCryptKeyServerHalf() ( serverHalf BlockCryptKeyServerHalf, err error) { var data [32]byte err = RandRead(data[:]) if err != nil { return BlockCryptKeyServerHalf{}, err } serverHalf = MakeBlockCryptKeyServerHalf(data) return serverHalf, nil }
go
func MakeRandomBlockCryptKeyServerHalf() ( serverHalf BlockCryptKeyServerHalf, err error) { var data [32]byte err = RandRead(data[:]) if err != nil { return BlockCryptKeyServerHalf{}, err } serverHalf = MakeBlockCryptKeyServerHalf(data) return serverHalf, nil }
[ "func", "MakeRandomBlockCryptKeyServerHalf", "(", ")", "(", "serverHalf", "BlockCryptKeyServerHalf", ",", "err", "error", ")", "{", "var", "data", "[", "32", "]", "byte", "\n", "err", "=", "RandRead", "(", "data", "[", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "BlockCryptKeyServerHalf", "{", "}", ",", "err", "\n", "}", "\n", "serverHalf", "=", "MakeBlockCryptKeyServerHalf", "(", "data", ")", "\n", "return", "serverHalf", ",", "nil", "\n", "}" ]
// MakeRandomBlockCryptKeyServerHalf generates the server-side of a // block crypt key.
[ "MakeRandomBlockCryptKeyServerHalf", "generates", "the", "server", "-", "side", "of", "a", "block", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L606-L615
160,045
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
ParseBlockCryptKeyServerHalf
func ParseBlockCryptKeyServerHalf(s string) (BlockCryptKeyServerHalf, error) { buf, err := hex.DecodeString(s) if err != nil { return BlockCryptKeyServerHalf{}, errors.WithStack(err) } var serverHalf BlockCryptKeyServerHalf err = serverHalf.UnmarshalBinary(buf) if err != nil { return BlockCryptKeyServerHalf{}, err } return serverHalf, nil }
go
func ParseBlockCryptKeyServerHalf(s string) (BlockCryptKeyServerHalf, error) { buf, err := hex.DecodeString(s) if err != nil { return BlockCryptKeyServerHalf{}, errors.WithStack(err) } var serverHalf BlockCryptKeyServerHalf err = serverHalf.UnmarshalBinary(buf) if err != nil { return BlockCryptKeyServerHalf{}, err } return serverHalf, nil }
[ "func", "ParseBlockCryptKeyServerHalf", "(", "s", "string", ")", "(", "BlockCryptKeyServerHalf", ",", "error", ")", "{", "buf", ",", "err", ":=", "hex", ".", "DecodeString", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "BlockCryptKeyServerHalf", "{", "}", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "var", "serverHalf", "BlockCryptKeyServerHalf", "\n", "err", "=", "serverHalf", ".", "UnmarshalBinary", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "BlockCryptKeyServerHalf", "{", "}", ",", "err", "\n", "}", "\n", "return", "serverHalf", ",", "nil", "\n", "}" ]
// ParseBlockCryptKeyServerHalf returns a BlockCryptKeyServerHalf // containing the given hex-encoded data, or an error.
[ "ParseBlockCryptKeyServerHalf", "returns", "a", "BlockCryptKeyServerHalf", "containing", "the", "given", "hex", "-", "encoded", "data", "or", "an", "error", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L619-L630
160,046
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MaskTLFCryptKey
func MaskTLFCryptKey(serverHalf TLFCryptKeyServerHalf, key TLFCryptKey) TLFCryptKeyClientHalf { return MakeTLFCryptKeyClientHalf(xorKeys(serverHalf.data, key.data)) }
go
func MaskTLFCryptKey(serverHalf TLFCryptKeyServerHalf, key TLFCryptKey) TLFCryptKeyClientHalf { return MakeTLFCryptKeyClientHalf(xorKeys(serverHalf.data, key.data)) }
[ "func", "MaskTLFCryptKey", "(", "serverHalf", "TLFCryptKeyServerHalf", ",", "key", "TLFCryptKey", ")", "TLFCryptKeyClientHalf", "{", "return", "MakeTLFCryptKeyClientHalf", "(", "xorKeys", "(", "serverHalf", ".", "data", ",", "key", ".", "data", ")", ")", "\n", "}" ]
// MaskTLFCryptKey returns the client side of a top-level folder crypt // key.
[ "MaskTLFCryptKey", "returns", "the", "client", "side", "of", "a", "top", "-", "level", "folder", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L662-L665
160,047
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
UnmaskTLFCryptKey
func UnmaskTLFCryptKey(serverHalf TLFCryptKeyServerHalf, clientHalf TLFCryptKeyClientHalf) TLFCryptKey { return MakeTLFCryptKey(xorKeys(serverHalf.data, clientHalf.data)) }
go
func UnmaskTLFCryptKey(serverHalf TLFCryptKeyServerHalf, clientHalf TLFCryptKeyClientHalf) TLFCryptKey { return MakeTLFCryptKey(xorKeys(serverHalf.data, clientHalf.data)) }
[ "func", "UnmaskTLFCryptKey", "(", "serverHalf", "TLFCryptKeyServerHalf", ",", "clientHalf", "TLFCryptKeyClientHalf", ")", "TLFCryptKey", "{", "return", "MakeTLFCryptKey", "(", "xorKeys", "(", "serverHalf", ".", "data", ",", "clientHalf", ".", "data", ")", ")", "\n", "}" ]
// UnmaskTLFCryptKey returns the top-level folder crypt key.
[ "UnmaskTLFCryptKey", "returns", "the", "top", "-", "level", "folder", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L668-L671
160,048
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
UnmaskBlockCryptKey
func UnmaskBlockCryptKey(serverHalf BlockCryptKeyServerHalf, tlfCryptKey TLFCryptKey) BlockCryptKey { return MakeBlockCryptKey(xorKeys(serverHalf.data, tlfCryptKey.data)) }
go
func UnmaskBlockCryptKey(serverHalf BlockCryptKeyServerHalf, tlfCryptKey TLFCryptKey) BlockCryptKey { return MakeBlockCryptKey(xorKeys(serverHalf.data, tlfCryptKey.data)) }
[ "func", "UnmaskBlockCryptKey", "(", "serverHalf", "BlockCryptKeyServerHalf", ",", "tlfCryptKey", "TLFCryptKey", ")", "BlockCryptKey", "{", "return", "MakeBlockCryptKey", "(", "xorKeys", "(", "serverHalf", ".", "data", ",", "tlfCryptKey", ".", "data", ")", ")", "\n", "}" ]
// UnmaskBlockCryptKey returns the block crypt key.
[ "UnmaskBlockCryptKey", "returns", "the", "block", "crypt", "key", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L674-L677
160,049
keybase/client
go/kbfs/kbfscrypto/crypto_key_types.go
MakeBlockHashKey
func MakeBlockHashKey( serverHalf BlockCryptKeyServerHalf, key TLFCryptKey) BlockHashKey { mac := hmac.New(sha512.New, key.Bytes()) mac.Write(serverHalf.Bytes()) hash := mac.Sum(nil) var hash64 [64]byte copy(hash64[:], hash) return BlockHashKey{privateByte64Container{hash64}} }
go
func MakeBlockHashKey( serverHalf BlockCryptKeyServerHalf, key TLFCryptKey) BlockHashKey { mac := hmac.New(sha512.New, key.Bytes()) mac.Write(serverHalf.Bytes()) hash := mac.Sum(nil) var hash64 [64]byte copy(hash64[:], hash) return BlockHashKey{privateByte64Container{hash64}} }
[ "func", "MakeBlockHashKey", "(", "serverHalf", "BlockCryptKeyServerHalf", ",", "key", "TLFCryptKey", ")", "BlockHashKey", "{", "mac", ":=", "hmac", ".", "New", "(", "sha512", ".", "New", ",", "key", ".", "Bytes", "(", ")", ")", "\n", "mac", ".", "Write", "(", "serverHalf", ".", "Bytes", "(", ")", ")", "\n", "hash", ":=", "mac", ".", "Sum", "(", "nil", ")", "\n", "var", "hash64", "[", "64", "]", "byte", "\n", "copy", "(", "hash64", "[", ":", "]", ",", "hash", ")", "\n", "return", "BlockHashKey", "{", "privateByte64Container", "{", "hash64", "}", "}", "\n", "}" ]
// MakeBlockHashKey makes a key used for encryption and decryption for // the v2 block encryption scheme.
[ "MakeBlockHashKey", "makes", "a", "key", "used", "for", "encryption", "and", "decryption", "for", "the", "v2", "block", "encryption", "scheme", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/crypto_key_types.go#L687-L695
160,050
keybase/client
go/kbfs/libkbfs/fetch_decider.go
Do
func (fd *fetchDecider) Do( ctx context.Context, bgTolerance, blockTolerance time.Duration, cachedTimestamp time.Time) (err error) { past := fd.Clock().Now().Sub(cachedTimestamp) switch { case past > blockTolerance || cachedTimestamp.IsZero(): fd.vlog.CLogf( ctx, libkb.VLog1, "Blocking on fetch; cached data is %s old", past) readyCh, errPtr := fd.launchBackgroundFetch(ctx) if fd.blockingForTest != nil { fd.blockingForTest <- struct{}{} } select { case <-readyCh: return *errPtr case <-ctx.Done(): return ctx.Err() } case past > bgTolerance: fd.vlog.CLogf(ctx, libkb.VLog1, "Cached data is %s old", past) _, _ = fd.launchBackgroundFetch(ctx) // Return immediately, with no error, since the caller can // just use the existing cache value. return nil default: fd.vlog.CLogf(ctx, libkb.VLog1, "Using cached data from %s ago", past) return nil } }
go
func (fd *fetchDecider) Do( ctx context.Context, bgTolerance, blockTolerance time.Duration, cachedTimestamp time.Time) (err error) { past := fd.Clock().Now().Sub(cachedTimestamp) switch { case past > blockTolerance || cachedTimestamp.IsZero(): fd.vlog.CLogf( ctx, libkb.VLog1, "Blocking on fetch; cached data is %s old", past) readyCh, errPtr := fd.launchBackgroundFetch(ctx) if fd.blockingForTest != nil { fd.blockingForTest <- struct{}{} } select { case <-readyCh: return *errPtr case <-ctx.Done(): return ctx.Err() } case past > bgTolerance: fd.vlog.CLogf(ctx, libkb.VLog1, "Cached data is %s old", past) _, _ = fd.launchBackgroundFetch(ctx) // Return immediately, with no error, since the caller can // just use the existing cache value. return nil default: fd.vlog.CLogf(ctx, libkb.VLog1, "Using cached data from %s ago", past) return nil } }
[ "func", "(", "fd", "*", "fetchDecider", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "bgTolerance", ",", "blockTolerance", "time", ".", "Duration", ",", "cachedTimestamp", "time", ".", "Time", ")", "(", "err", "error", ")", "{", "past", ":=", "fd", ".", "Clock", "(", ")", ".", "Now", "(", ")", ".", "Sub", "(", "cachedTimestamp", ")", "\n", "switch", "{", "case", "past", ">", "blockTolerance", "||", "cachedTimestamp", ".", "IsZero", "(", ")", ":", "fd", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "past", ")", "\n", "readyCh", ",", "errPtr", ":=", "fd", ".", "launchBackgroundFetch", "(", "ctx", ")", "\n\n", "if", "fd", ".", "blockingForTest", "!=", "nil", "{", "fd", ".", "blockingForTest", "<-", "struct", "{", "}", "{", "}", "\n", "}", "\n\n", "select", "{", "case", "<-", "readyCh", ":", "return", "*", "errPtr", "\n", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "ctx", ".", "Err", "(", ")", "\n", "}", "\n", "case", "past", ">", "bgTolerance", ":", "fd", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "past", ")", "\n", "_", ",", "_", "=", "fd", ".", "launchBackgroundFetch", "(", "ctx", ")", "\n", "// Return immediately, with no error, since the caller can", "// just use the existing cache value.", "return", "nil", "\n", "default", ":", "fd", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "past", ")", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Do decides whether to block on a fetch, launch a background fetch // and use existing cached value, or simply use the existing cached // value with no more fetching. The caller can provide a positive // tolerance, to accept stale LimitBytes and UsageBytes data. If // tolerance is 0 or negative, this always makes a blocking call using // `fd.fetcher`. // // 1) If the age of cached data is more than blockTolerance, it blocks // until a new value is fetched and ready in the caller's cache. // 2) Otherwise, if the age of cached data is more than bgTolerance, // a background RPC is spawned to refresh cached data using `fd.fetcher`, // but returns immediately to let the caller use stale data. // 3) Otherwise, it returns immediately
[ "Do", "decides", "whether", "to", "block", "on", "a", "fetch", "launch", "a", "background", "fetch", "and", "use", "existing", "cached", "value", "or", "simply", "use", "the", "existing", "cached", "value", "with", "no", "more", "fetching", ".", "The", "caller", "can", "provide", "a", "positive", "tolerance", "to", "accept", "stale", "LimitBytes", "and", "UsageBytes", "data", ".", "If", "tolerance", "is", "0", "or", "negative", "this", "always", "makes", "a", "blocking", "call", "using", "fd", ".", "fetcher", ".", "1", ")", "If", "the", "age", "of", "cached", "data", "is", "more", "than", "blockTolerance", "it", "blocks", "until", "a", "new", "value", "is", "fetched", "and", "ready", "in", "the", "caller", "s", "cache", ".", "2", ")", "Otherwise", "if", "the", "age", "of", "cached", "data", "is", "more", "than", "bgTolerance", "a", "background", "RPC", "is", "spawned", "to", "refresh", "cached", "data", "using", "fd", ".", "fetcher", "but", "returns", "immediately", "to", "let", "the", "caller", "use", "stale", "data", ".", "3", ")", "Otherwise", "it", "returns", "immediately" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/fetch_decider.go#L114-L144
160,051
keybase/client
go/kbfs/libfs/fs.go
NewUnwrappedFS
func NewUnwrappedFS(ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle, branch data.BranchName, subdir string, uniqID string, priority keybase1.MDPriority) (*FS, error) { return newFS( ctx, config, tlfHandle, branch, subdir, uniqID, priority, true, readwrite) }
go
func NewUnwrappedFS(ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle, branch data.BranchName, subdir string, uniqID string, priority keybase1.MDPriority) (*FS, error) { return newFS( ctx, config, tlfHandle, branch, subdir, uniqID, priority, true, readwrite) }
[ "func", "NewUnwrappedFS", "(", "ctx", "context", ".", "Context", ",", "config", "libkbfs", ".", "Config", ",", "tlfHandle", "*", "tlfhandle", ".", "Handle", ",", "branch", "data", ".", "BranchName", ",", "subdir", "string", ",", "uniqID", "string", ",", "priority", "keybase1", ".", "MDPriority", ")", "(", "*", "FS", ",", "error", ")", "{", "return", "newFS", "(", "ctx", ",", "config", ",", "tlfHandle", ",", "branch", ",", "subdir", ",", "uniqID", ",", "priority", ",", "true", ",", "readwrite", ")", "\n", "}" ]
// NewUnwrappedFS returns a new FS instance, chroot'd to the given TLF // and subdir within that TLF, but all the nodes are unwrapped. // `subdir` must exist, and point to a directory, before this function // is called. `uniqID` needs to uniquely identify this instance among // all users of this TLF globally; for example, a device ID combined // with a local tempfile name is recommended.
[ "NewUnwrappedFS", "returns", "a", "new", "FS", "instance", "chroot", "d", "to", "the", "given", "TLF", "and", "subdir", "within", "that", "TLF", "but", "all", "the", "nodes", "are", "unwrapped", ".", "subdir", "must", "exist", "and", "point", "to", "a", "directory", "before", "this", "function", "is", "called", ".", "uniqID", "needs", "to", "uniquely", "identify", "this", "instance", "among", "all", "users", "of", "this", "TLF", "globally", ";", "for", "example", "a", "device", "ID", "combined", "with", "a", "local", "tempfile", "name", "is", "recommended", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L244-L250
160,052
keybase/client
go/kbfs/libfs/fs.go
lookupOrCreateEntryNoFollow
func (fs *FS) lookupOrCreateEntryNoFollow( dir libkbfs.Node, filename string, flag int, perm os.FileMode) ( libkbfs.Node, data.EntryInfo, error) { n, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, dir, filename) switch errors.Cause(err).(type) { case idutil.NoSuchNameError: // The file doesn't exist yet; create if requested if flag&os.O_CREATE == 0 { return nil, data.EntryInfo{}, err } fs.log.CDebugf( fs.ctx, "Creating %s since it doesn't exist yet", filename) excl := libkbfs.NoExcl if flag&os.O_EXCL != 0 { excl = libkbfs.WithExcl } isExec := (perm & 0100) != 0 n, ei, err = fs.config.KBFSOps().CreateFile( fs.ctx, dir, filename, isExec, excl) switch errors.Cause(err).(type) { case data.NameExistsError: // Someone made it already; recurse to try the lookup again. fs.log.CDebugf( fs.ctx, "Attempting lookup again after failed create") return fs.lookupOrCreateEntryNoFollow(dir, filename, flag, perm) case nil: return n, ei, nil default: return nil, data.EntryInfo{}, err } case nil: // If we were supposed to have exclusively-created this file, // we must fail. if flag&os.O_CREATE != 0 && flag&os.O_EXCL != 0 { return nil, data.EntryInfo{}, errors.New("Exclusive create failed because the file exists") } if ei.Type == data.Sym { // The caller must retry if desired. return nil, ei, nil } return n, ei, nil default: return nil, data.EntryInfo{}, err } }
go
func (fs *FS) lookupOrCreateEntryNoFollow( dir libkbfs.Node, filename string, flag int, perm os.FileMode) ( libkbfs.Node, data.EntryInfo, error) { n, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, dir, filename) switch errors.Cause(err).(type) { case idutil.NoSuchNameError: // The file doesn't exist yet; create if requested if flag&os.O_CREATE == 0 { return nil, data.EntryInfo{}, err } fs.log.CDebugf( fs.ctx, "Creating %s since it doesn't exist yet", filename) excl := libkbfs.NoExcl if flag&os.O_EXCL != 0 { excl = libkbfs.WithExcl } isExec := (perm & 0100) != 0 n, ei, err = fs.config.KBFSOps().CreateFile( fs.ctx, dir, filename, isExec, excl) switch errors.Cause(err).(type) { case data.NameExistsError: // Someone made it already; recurse to try the lookup again. fs.log.CDebugf( fs.ctx, "Attempting lookup again after failed create") return fs.lookupOrCreateEntryNoFollow(dir, filename, flag, perm) case nil: return n, ei, nil default: return nil, data.EntryInfo{}, err } case nil: // If we were supposed to have exclusively-created this file, // we must fail. if flag&os.O_CREATE != 0 && flag&os.O_EXCL != 0 { return nil, data.EntryInfo{}, errors.New("Exclusive create failed because the file exists") } if ei.Type == data.Sym { // The caller must retry if desired. return nil, ei, nil } return n, ei, nil default: return nil, data.EntryInfo{}, err } }
[ "func", "(", "fs", "*", "FS", ")", "lookupOrCreateEntryNoFollow", "(", "dir", "libkbfs", ".", "Node", ",", "filename", "string", ",", "flag", "int", ",", "perm", "os", ".", "FileMode", ")", "(", "libkbfs", ".", "Node", ",", "data", ".", "EntryInfo", ",", "error", ")", "{", "n", ",", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Lookup", "(", "fs", ".", "ctx", ",", "dir", ",", "filename", ")", "\n", "switch", "errors", ".", "Cause", "(", "err", ")", ".", "(", "type", ")", "{", "case", "idutil", ".", "NoSuchNameError", ":", "// The file doesn't exist yet; create if requested", "if", "flag", "&", "os", ".", "O_CREATE", "==", "0", "{", "return", "nil", ",", "data", ".", "EntryInfo", "{", "}", ",", "err", "\n", "}", "\n", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ")", "\n", "excl", ":=", "libkbfs", ".", "NoExcl", "\n", "if", "flag", "&", "os", ".", "O_EXCL", "!=", "0", "{", "excl", "=", "libkbfs", ".", "WithExcl", "\n", "}", "\n", "isExec", ":=", "(", "perm", "&", "0100", ")", "!=", "0", "\n", "n", ",", "ei", ",", "err", "=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "CreateFile", "(", "fs", ".", "ctx", ",", "dir", ",", "filename", ",", "isExec", ",", "excl", ")", "\n", "switch", "errors", ".", "Cause", "(", "err", ")", ".", "(", "type", ")", "{", "case", "data", ".", "NameExistsError", ":", "// Someone made it already; recurse to try the lookup again.", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ")", "\n", "return", "fs", ".", "lookupOrCreateEntryNoFollow", "(", "dir", ",", "filename", ",", "flag", ",", "perm", ")", "\n", "case", "nil", ":", "return", "n", ",", "ei", ",", "nil", "\n", "default", ":", "return", "nil", ",", "data", ".", "EntryInfo", "{", "}", ",", "err", "\n", "}", "\n", "case", "nil", ":", "// If we were supposed to have exclusively-created this file,", "// we must fail.", "if", "flag", "&", "os", ".", "O_CREATE", "!=", "0", "&&", "flag", "&", "os", ".", "O_EXCL", "!=", "0", "{", "return", "nil", ",", "data", ".", "EntryInfo", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "ei", ".", "Type", "==", "data", ".", "Sym", "{", "// The caller must retry if desired.", "return", "nil", ",", "ei", ",", "nil", "\n", "}", "\n\n", "return", "n", ",", "ei", ",", "nil", "\n", "default", ":", "return", "nil", ",", "data", ".", "EntryInfo", "{", "}", ",", "err", "\n", "}", "\n", "}" ]
// lookupOrCreateEntryNoFollow looks up the entry for a file in a // given parent node. If the entry is a symlink, it will return a nil // Node and a nil error. If the entry doesn't exist and O_CREATE is // set in `flag`, it will create the entry as a file.
[ "lookupOrCreateEntryNoFollow", "looks", "up", "the", "entry", "for", "a", "file", "in", "a", "given", "parent", "node", ".", "If", "the", "entry", "is", "a", "symlink", "it", "will", "return", "a", "nil", "Node", "and", "a", "nil", "error", ".", "If", "the", "entry", "doesn", "t", "exist", "and", "O_CREATE", "is", "set", "in", "flag", "it", "will", "create", "the", "entry", "as", "a", "file", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L308-L355
160,053
keybase/client
go/kbfs/libfs/fs.go
lookupParentWithDepth
func (fs *FS) lookupParentWithDepth( filename string, exitEarly bool, depth int) ( parent libkbfs.Node, parentDir, base string, err error) { parts := strings.Split(filename, "/") n := fs.root // Iterate through each of the parent directories of the file, but // not the file itself. for i := 0; i < len(parts)-1; i++ { p := parts[i] nextNode, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, p) switch errors.Cause(err).(type) { case idutil.NoSuchNameError: if exitEarly { parentDir = path.Join(parts[:i]...) base = path.Join(parts[i:]...) return n, parentDir, base, nil } return nil, "", "", err case nil: n = nextNode default: return nil, "", "", err } switch ei.Type { case data.Sym: if depth == maxSymlinkLevels { return nil, "", "", errors.New("Too many levels of symlinks") } parentDir = path.Join(parts[:i]...) newPath, err := followSymlink(parentDir, ei.SymPath) if err != nil { return nil, "", "", err } newPathPlusRemainder := append([]string{newPath}, parts[i+1:]...) return fs.lookupParentWithDepth( path.Join(newPathPlusRemainder...), exitEarly, depth+1) case data.Dir: continue default: return nil, "", "", ErrNotADirectory{Name: path.Join(parts[:i+1]...)} } } parentDir = path.Join(parts[:len(parts)-1]...) base = parts[len(parts)-1] return n, parentDir, base, nil }
go
func (fs *FS) lookupParentWithDepth( filename string, exitEarly bool, depth int) ( parent libkbfs.Node, parentDir, base string, err error) { parts := strings.Split(filename, "/") n := fs.root // Iterate through each of the parent directories of the file, but // not the file itself. for i := 0; i < len(parts)-1; i++ { p := parts[i] nextNode, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, p) switch errors.Cause(err).(type) { case idutil.NoSuchNameError: if exitEarly { parentDir = path.Join(parts[:i]...) base = path.Join(parts[i:]...) return n, parentDir, base, nil } return nil, "", "", err case nil: n = nextNode default: return nil, "", "", err } switch ei.Type { case data.Sym: if depth == maxSymlinkLevels { return nil, "", "", errors.New("Too many levels of symlinks") } parentDir = path.Join(parts[:i]...) newPath, err := followSymlink(parentDir, ei.SymPath) if err != nil { return nil, "", "", err } newPathPlusRemainder := append([]string{newPath}, parts[i+1:]...) return fs.lookupParentWithDepth( path.Join(newPathPlusRemainder...), exitEarly, depth+1) case data.Dir: continue default: return nil, "", "", ErrNotADirectory{Name: path.Join(parts[:i+1]...)} } } parentDir = path.Join(parts[:len(parts)-1]...) base = parts[len(parts)-1] return n, parentDir, base, nil }
[ "func", "(", "fs", "*", "FS", ")", "lookupParentWithDepth", "(", "filename", "string", ",", "exitEarly", "bool", ",", "depth", "int", ")", "(", "parent", "libkbfs", ".", "Node", ",", "parentDir", ",", "base", "string", ",", "err", "error", ")", "{", "parts", ":=", "strings", ".", "Split", "(", "filename", ",", "\"", "\"", ")", "\n", "n", ":=", "fs", ".", "root", "\n", "// Iterate through each of the parent directories of the file, but", "// not the file itself.", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "parts", ")", "-", "1", ";", "i", "++", "{", "p", ":=", "parts", "[", "i", "]", "\n", "nextNode", ",", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Lookup", "(", "fs", ".", "ctx", ",", "n", ",", "p", ")", "\n", "switch", "errors", ".", "Cause", "(", "err", ")", ".", "(", "type", ")", "{", "case", "idutil", ".", "NoSuchNameError", ":", "if", "exitEarly", "{", "parentDir", "=", "path", ".", "Join", "(", "parts", "[", ":", "i", "]", "...", ")", "\n", "base", "=", "path", ".", "Join", "(", "parts", "[", "i", ":", "]", "...", ")", "\n", "return", "n", ",", "parentDir", ",", "base", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "case", "nil", ":", "n", "=", "nextNode", "\n", "default", ":", "return", "nil", ",", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "switch", "ei", ".", "Type", "{", "case", "data", ".", "Sym", ":", "if", "depth", "==", "maxSymlinkLevels", "{", "return", "nil", ",", "\"", "\"", ",", "\"", "\"", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "parentDir", "=", "path", ".", "Join", "(", "parts", "[", ":", "i", "]", "...", ")", "\n", "newPath", ",", "err", ":=", "followSymlink", "(", "parentDir", ",", "ei", ".", "SymPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "newPathPlusRemainder", ":=", "append", "(", "[", "]", "string", "{", "newPath", "}", ",", "parts", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "fs", ".", "lookupParentWithDepth", "(", "path", ".", "Join", "(", "newPathPlusRemainder", "...", ")", ",", "exitEarly", ",", "depth", "+", "1", ")", "\n", "case", "data", ".", "Dir", ":", "continue", "\n", "default", ":", "return", "nil", ",", "\"", "\"", ",", "\"", "\"", ",", "ErrNotADirectory", "{", "Name", ":", "path", ".", "Join", "(", "parts", "[", ":", "i", "+", "1", "]", "...", ")", "}", "\n", "}", "\n", "}", "\n\n", "parentDir", "=", "path", ".", "Join", "(", "parts", "[", ":", "len", "(", "parts", ")", "-", "1", "]", "...", ")", "\n", "base", "=", "parts", "[", "len", "(", "parts", ")", "-", "1", "]", "\n", "return", "n", ",", "parentDir", ",", "base", ",", "nil", "\n", "}" ]
// lookupParentWithDepth looks up the parent node of the given // filename. It follows symlinks in the path, but doesn't resolve the // final base name. If `exitEarly` is true, it returns on the first // not-found error and `base` will contain the subpath of filename not // yet found.
[ "lookupParentWithDepth", "looks", "up", "the", "parent", "node", "of", "the", "given", "filename", ".", "It", "follows", "symlinks", "in", "the", "path", "but", "doesn", "t", "resolve", "the", "final", "base", "name", ".", "If", "exitEarly", "is", "true", "it", "returns", "on", "the", "first", "not", "-", "found", "error", "and", "base", "will", "contain", "the", "subpath", "of", "filename", "not", "yet", "found", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L362-L409
160,054
keybase/client
go/kbfs/libfs/fs.go
OpenFile
func (fs *FS) OpenFile(filename string, flag int, perm os.FileMode) ( f billy.File, err error) { fs.log.CDebugf( fs.ctx, "OpenFile %s, flag=%d, perm=%o", filename, flag, perm) defer func() { fs.deferLog.CDebugf(fs.ctx, "OpenFile done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return nil, err } err = fs.ensureParentDir(filename) if err != nil { return nil, err } n, ei, err := fs.lookupOrCreateEntry(filename, flag, perm) if err != nil { return nil, err } // Make sure this is a file. if !ei.Type.IsFile() { return nil, errors.Errorf("%s is not a file", filename) } if flag&os.O_TRUNC != 0 { err := fs.config.KBFSOps().Truncate(fs.ctx, n, 0) if err != nil { return nil, err } } offset := int64(0) if flag&os.O_APPEND != 0 { if ei.Size >= uint64(1<<63) { return nil, errors.New("offset too large") } offset = int64(ei.Size) } return &File{ fs: fs, filename: filename, node: n, readOnly: flag == os.O_RDONLY, offset: offset, }, nil }
go
func (fs *FS) OpenFile(filename string, flag int, perm os.FileMode) ( f billy.File, err error) { fs.log.CDebugf( fs.ctx, "OpenFile %s, flag=%d, perm=%o", filename, flag, perm) defer func() { fs.deferLog.CDebugf(fs.ctx, "OpenFile done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return nil, err } err = fs.ensureParentDir(filename) if err != nil { return nil, err } n, ei, err := fs.lookupOrCreateEntry(filename, flag, perm) if err != nil { return nil, err } // Make sure this is a file. if !ei.Type.IsFile() { return nil, errors.Errorf("%s is not a file", filename) } if flag&os.O_TRUNC != 0 { err := fs.config.KBFSOps().Truncate(fs.ctx, n, 0) if err != nil { return nil, err } } offset := int64(0) if flag&os.O_APPEND != 0 { if ei.Size >= uint64(1<<63) { return nil, errors.New("offset too large") } offset = int64(ei.Size) } return &File{ fs: fs, filename: filename, node: n, readOnly: flag == os.O_RDONLY, offset: offset, }, nil }
[ "func", "(", "fs", "*", "FS", ")", "OpenFile", "(", "filename", "string", ",", "flag", "int", ",", "perm", "os", ".", "FileMode", ")", "(", "f", "billy", ".", "File", ",", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ",", "flag", ",", "perm", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "fs", ".", "ensureParentDir", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ",", "ei", ",", "err", ":=", "fs", ".", "lookupOrCreateEntry", "(", "filename", ",", "flag", ",", "perm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Make sure this is a file.", "if", "!", "ei", ".", "Type", ".", "IsFile", "(", ")", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "filename", ")", "\n", "}", "\n\n", "if", "flag", "&", "os", ".", "O_TRUNC", "!=", "0", "{", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Truncate", "(", "fs", ".", "ctx", ",", "n", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "offset", ":=", "int64", "(", "0", ")", "\n", "if", "flag", "&", "os", ".", "O_APPEND", "!=", "0", "{", "if", "ei", ".", "Size", ">=", "uint64", "(", "1", "<<", "63", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "offset", "=", "int64", "(", "ei", ".", "Size", ")", "\n", "}", "\n\n", "return", "&", "File", "{", "fs", ":", "fs", ",", "filename", ":", "filename", ",", "node", ":", "n", ",", "readOnly", ":", "flag", "==", "os", ".", "O_RDONLY", ",", "offset", ":", "offset", ",", "}", ",", "nil", "\n", "}" ]
// OpenFile implements the billy.Filesystem interface for FS.
[ "OpenFile", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L533-L583
160,055
keybase/client
go/kbfs/libfs/fs.go
Create
func (fs *FS) Create(filename string) (billy.File, error) { return fs.OpenFile(filename, os.O_CREATE, 0600) }
go
func (fs *FS) Create(filename string) (billy.File, error) { return fs.OpenFile(filename, os.O_CREATE, 0600) }
[ "func", "(", "fs", "*", "FS", ")", "Create", "(", "filename", "string", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "fs", ".", "OpenFile", "(", "filename", ",", "os", ".", "O_CREATE", ",", "0600", ")", "\n", "}" ]
// Create implements the billy.Filesystem interface for FS.
[ "Create", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L586-L588
160,056
keybase/client
go/kbfs/libfs/fs.go
Open
func (fs *FS) Open(filename string) (billy.File, error) { return fs.OpenFile(filename, os.O_RDONLY, 0600) }
go
func (fs *FS) Open(filename string) (billy.File, error) { return fs.OpenFile(filename, os.O_RDONLY, 0600) }
[ "func", "(", "fs", "*", "FS", ")", "Open", "(", "filename", "string", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "return", "fs", ".", "OpenFile", "(", "filename", ",", "os", ".", "O_RDONLY", ",", "0600", ")", "\n", "}" ]
// Open implements the billy.Filesystem interface for FS.
[ "Open", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L591-L593
160,057
keybase/client
go/kbfs/libfs/fs.go
Stat
func (fs *FS) Stat(filename string) (fi os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "Stat %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Stat done: %+v", err) err = translateErr(err) }() if fs.empty && (filename == "" || filename == ".") { // We can't just uncondionally use FileInfoFast here as that'd result // in WritePerm unset for non-existent TLFs. return fs.makeFileInfo(data.EntryInfo{ Type: data.Dir, }, nil, filename), nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, ei, err := fs.lookupOrCreateEntry(filename, os.O_RDONLY, 0) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, n.GetBasename()), nil }
go
func (fs *FS) Stat(filename string) (fi os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "Stat %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Stat done: %+v", err) err = translateErr(err) }() if fs.empty && (filename == "" || filename == ".") { // We can't just uncondionally use FileInfoFast here as that'd result // in WritePerm unset for non-existent TLFs. return fs.makeFileInfo(data.EntryInfo{ Type: data.Dir, }, nil, filename), nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, ei, err := fs.lookupOrCreateEntry(filename, os.O_RDONLY, 0) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, n.GetBasename()), nil }
[ "func", "(", "fs", "*", "FS", ")", "Stat", "(", "filename", "string", ")", "(", "fi", "os", ".", "FileInfo", ",", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "fs", ".", "empty", "&&", "(", "filename", "==", "\"", "\"", "||", "filename", "==", "\"", "\"", ")", "{", "// We can't just uncondionally use FileInfoFast here as that'd result", "// in WritePerm unset for non-existent TLFs.", "return", "fs", ".", "makeFileInfo", "(", "data", ".", "EntryInfo", "{", "Type", ":", "data", ".", "Dir", ",", "}", ",", "nil", ",", "filename", ")", ",", "nil", "\n", "}", "else", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ",", "ei", ",", "err", ":=", "fs", ".", "lookupOrCreateEntry", "(", "filename", ",", "os", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "fs", ".", "makeFileInfo", "(", "ei", ",", "n", ",", "n", ".", "GetBasename", "(", ")", ")", ",", "nil", "\n", "}" ]
// Stat implements the billy.Filesystem interface for FS.
[ "Stat", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L612-L635
160,058
keybase/client
go/kbfs/libfs/fs.go
Rename
func (fs *FS) Rename(oldpath, newpath string) (err error) { fs.log.CDebugf(fs.ctx, "Rename %s -> %s", oldpath, newpath) defer func() { fs.deferLog.CDebugf(fs.ctx, "Rename done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } err = fs.mkdirAll(path.Dir(newpath), 0755) if err != nil && !os.IsExist(err) { return err } oldParent, _, oldBase, err := fs.lookupParent(oldpath) if err != nil { return err } newParent, _, newBase, err := fs.lookupParent(newpath) if err != nil { return err } return fs.config.KBFSOps().Rename( fs.ctx, oldParent, oldBase, newParent, newBase) }
go
func (fs *FS) Rename(oldpath, newpath string) (err error) { fs.log.CDebugf(fs.ctx, "Rename %s -> %s", oldpath, newpath) defer func() { fs.deferLog.CDebugf(fs.ctx, "Rename done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } err = fs.mkdirAll(path.Dir(newpath), 0755) if err != nil && !os.IsExist(err) { return err } oldParent, _, oldBase, err := fs.lookupParent(oldpath) if err != nil { return err } newParent, _, newBase, err := fs.lookupParent(newpath) if err != nil { return err } return fs.config.KBFSOps().Rename( fs.ctx, oldParent, oldBase, newParent, newBase) }
[ "func", "(", "fs", "*", "FS", ")", "Rename", "(", "oldpath", ",", "newpath", "string", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "oldpath", ",", "newpath", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "fs", ".", "mkdirAll", "(", "path", ".", "Dir", "(", "newpath", ")", ",", "0755", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "os", ".", "IsExist", "(", "err", ")", "{", "return", "err", "\n", "}", "\n\n", "oldParent", ",", "_", ",", "oldBase", ",", "err", ":=", "fs", ".", "lookupParent", "(", "oldpath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "newParent", ",", "_", ",", "newBase", ",", "err", ":=", "fs", ".", "lookupParent", "(", "newpath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Rename", "(", "fs", ".", "ctx", ",", "oldParent", ",", "oldBase", ",", "newParent", ",", "newBase", ")", "\n", "}" ]
// Rename implements the billy.Filesystem interface for FS.
[ "Rename", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L638-L666
160,059
keybase/client
go/kbfs/libfs/fs.go
Remove
func (fs *FS) Remove(filename string) (err error) { fs.log.CDebugf(fs.ctx, "Remove %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Remove done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } parent, _, base, err := fs.lookupParent(filename) if err != nil { return err } _, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, parent, base) if err != nil { return err } if ei.Type == data.Dir { return fs.config.KBFSOps().RemoveDir(fs.ctx, parent, base) } return fs.config.KBFSOps().RemoveEntry(fs.ctx, parent, base) }
go
func (fs *FS) Remove(filename string) (err error) { fs.log.CDebugf(fs.ctx, "Remove %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Remove done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } parent, _, base, err := fs.lookupParent(filename) if err != nil { return err } _, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, parent, base) if err != nil { return err } if ei.Type == data.Dir { return fs.config.KBFSOps().RemoveDir(fs.ctx, parent, base) } return fs.config.KBFSOps().RemoveEntry(fs.ctx, parent, base) }
[ "func", "(", "fs", "*", "FS", ")", "Remove", "(", "filename", "string", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "parent", ",", "_", ",", "base", ",", "err", ":=", "fs", ".", "lookupParent", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Lookup", "(", "fs", ".", "ctx", ",", "parent", ",", "base", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "ei", ".", "Type", "==", "data", ".", "Dir", "{", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "RemoveDir", "(", "fs", ".", "ctx", ",", "parent", ",", "base", ")", "\n", "}", "\n", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "RemoveEntry", "(", "fs", ".", "ctx", ",", "parent", ",", "base", ")", "\n", "}" ]
// Remove implements the billy.Filesystem interface for FS.
[ "Remove", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L669-L694
160,060
keybase/client
go/kbfs/libfs/fs.go
Join
func (fs *FS) Join(elem ...string) string { return path.Clean(path.Join(elem...)) }
go
func (fs *FS) Join(elem ...string) string { return path.Clean(path.Join(elem...)) }
[ "func", "(", "fs", "*", "FS", ")", "Join", "(", "elem", "...", "string", ")", "string", "{", "return", "path", ".", "Clean", "(", "path", ".", "Join", "(", "elem", "...", ")", ")", "\n", "}" ]
// Join implements the billy.Filesystem interface for FS.
[ "Join", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L697-L699
160,061
keybase/client
go/kbfs/libfs/fs.go
TempFile
func (fs *FS) TempFile(dir, prefix string) (billy.File, error) { if err := fs.requireNonEmpty(); err != nil { return nil, err } // We'd have to turn off journaling to support TempFile perfectly, // but the given uniq ID and a random number should be good // enough. Especially since most users will end up renaming the // temp file before journal flushing even happens. b := make([]byte, 8) _, err := rand.Read(b) if err != nil { return nil, err } suffix := fs.uniqID + "-" + base64.URLEncoding.EncodeToString(b) return fs.OpenFile(path.Join(dir, prefix+suffix), os.O_CREATE|os.O_EXCL, 0600) }
go
func (fs *FS) TempFile(dir, prefix string) (billy.File, error) { if err := fs.requireNonEmpty(); err != nil { return nil, err } // We'd have to turn off journaling to support TempFile perfectly, // but the given uniq ID and a random number should be good // enough. Especially since most users will end up renaming the // temp file before journal flushing even happens. b := make([]byte, 8) _, err := rand.Read(b) if err != nil { return nil, err } suffix := fs.uniqID + "-" + base64.URLEncoding.EncodeToString(b) return fs.OpenFile(path.Join(dir, prefix+suffix), os.O_CREATE|os.O_EXCL, 0600) }
[ "func", "(", "fs", "*", "FS", ")", "TempFile", "(", "dir", ",", "prefix", "string", ")", "(", "billy", ".", "File", ",", "error", ")", "{", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// We'd have to turn off journaling to support TempFile perfectly,", "// but the given uniq ID and a random number should be good", "// enough. Especially since most users will end up renaming the", "// temp file before journal flushing even happens.", "b", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "_", ",", "err", ":=", "rand", ".", "Read", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "suffix", ":=", "fs", ".", "uniqID", "+", "\"", "\"", "+", "base64", ".", "URLEncoding", ".", "EncodeToString", "(", "b", ")", "\n", "return", "fs", ".", "OpenFile", "(", "path", ".", "Join", "(", "dir", ",", "prefix", "+", "suffix", ")", ",", "os", ".", "O_CREATE", "|", "os", ".", "O_EXCL", ",", "0600", ")", "\n", "}" ]
// TempFile implements the billy.Filesystem interface for FS.
[ "TempFile", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L702-L719
160,062
keybase/client
go/kbfs/libfs/fs.go
ReadDir
func (fs *FS) ReadDir(p string) (fis []os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "ReadDir %s", p) defer func() { fs.deferLog.CDebugf(fs.ctx, "ReadDir done: %+v", err) err = translateErr(err) }() if fs.empty && (p == "" || p == "." || p == "/") { return nil, nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, _, err := fs.lookupOrCreateEntry(p, os.O_RDONLY, 0) if err != nil { return nil, err } return fs.readDir(n) }
go
func (fs *FS) ReadDir(p string) (fis []os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "ReadDir %s", p) defer func() { fs.deferLog.CDebugf(fs.ctx, "ReadDir done: %+v", err) err = translateErr(err) }() if fs.empty && (p == "" || p == "." || p == "/") { return nil, nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, _, err := fs.lookupOrCreateEntry(p, os.O_RDONLY, 0) if err != nil { return nil, err } return fs.readDir(n) }
[ "func", "(", "fs", "*", "FS", ")", "ReadDir", "(", "p", "string", ")", "(", "fis", "[", "]", "os", ".", "FileInfo", ",", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "p", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "fs", ".", "empty", "&&", "(", "p", "==", "\"", "\"", "||", "p", "==", "\"", "\"", "||", "p", "==", "\"", "\"", ")", "{", "return", "nil", ",", "nil", "\n", "}", "else", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "err", ":=", "fs", ".", "lookupOrCreateEntry", "(", "p", ",", "os", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "fs", ".", "readDir", "(", "n", ")", "\n", "}" ]
// ReadDir implements the billy.Filesystem interface for FS.
[ "ReadDir", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L743-L761
160,063
keybase/client
go/kbfs/libfs/fs.go
MkdirAll
func (fs *FS) MkdirAll(filename string, perm os.FileMode) (err error) { fs.log.CDebugf(fs.ctx, "MkdirAll %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "MkdirAll done: %+v", err) }() if err := fs.requireNonEmpty(); err != nil { return err } return fs.mkdirAll(filename, perm) }
go
func (fs *FS) MkdirAll(filename string, perm os.FileMode) (err error) { fs.log.CDebugf(fs.ctx, "MkdirAll %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "MkdirAll done: %+v", err) }() if err := fs.requireNonEmpty(); err != nil { return err } return fs.mkdirAll(filename, perm) }
[ "func", "(", "fs", "*", "FS", ")", "MkdirAll", "(", "filename", "string", ",", "perm", "os", ".", "FileMode", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "fs", ".", "mkdirAll", "(", "filename", ",", "perm", ")", "\n", "}" ]
// MkdirAll implements the billy.Filesystem interface for FS.
[ "MkdirAll", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L764-L775
160,064
keybase/client
go/kbfs/libfs/fs.go
Lstat
func (fs *FS) Lstat(filename string) (fi os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "Lstat %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Lstat done: %+v", err) err = translateErr(err) }() if fs.empty && (filename == "" || filename == ".") { // We can't just uncondionally use FileInfoFast here as that'd result // in WritePerm unset for non-existent TLFs. return fs.makeFileInfo(data.EntryInfo{ Type: data.Dir, }, nil, filename), nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, _, base, err := fs.lookupParent(filename) if err != nil { return nil, err } if base == "" { ei, err := fs.config.KBFSOps().Stat(fs.ctx, n) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, ""), nil } n, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, base) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, base), nil }
go
func (fs *FS) Lstat(filename string) (fi os.FileInfo, err error) { fs.log.CDebugf(fs.ctx, "Lstat %s", filename) defer func() { fs.deferLog.CDebugf(fs.ctx, "Lstat done: %+v", err) err = translateErr(err) }() if fs.empty && (filename == "" || filename == ".") { // We can't just uncondionally use FileInfoFast here as that'd result // in WritePerm unset for non-existent TLFs. return fs.makeFileInfo(data.EntryInfo{ Type: data.Dir, }, nil, filename), nil } else if err := fs.requireNonEmpty(); err != nil { return nil, err } n, _, base, err := fs.lookupParent(filename) if err != nil { return nil, err } if base == "" { ei, err := fs.config.KBFSOps().Stat(fs.ctx, n) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, ""), nil } n, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, base) if err != nil { return nil, err } return fs.makeFileInfo(ei, n, base), nil }
[ "func", "(", "fs", "*", "FS", ")", "Lstat", "(", "filename", "string", ")", "(", "fi", "os", ".", "FileInfo", ",", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "filename", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "fs", ".", "empty", "&&", "(", "filename", "==", "\"", "\"", "||", "filename", "==", "\"", "\"", ")", "{", "// We can't just uncondionally use FileInfoFast here as that'd result", "// in WritePerm unset for non-existent TLFs.", "return", "fs", ".", "makeFileInfo", "(", "data", ".", "EntryInfo", "{", "Type", ":", "data", ".", "Dir", ",", "}", ",", "nil", ",", "filename", ")", ",", "nil", "\n", "}", "else", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "base", ",", "err", ":=", "fs", ".", "lookupParent", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "base", "==", "\"", "\"", "{", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Stat", "(", "fs", ".", "ctx", ",", "n", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "fs", ".", "makeFileInfo", "(", "ei", ",", "n", ",", "\"", "\"", ")", ",", "nil", "\n", "}", "\n\n", "n", ",", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Lookup", "(", "fs", ".", "ctx", ",", "n", ",", "base", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "fs", ".", "makeFileInfo", "(", "ei", ",", "n", ",", "base", ")", ",", "nil", "\n", "}" ]
// Lstat implements the billy.Filesystem interface for FS.
[ "Lstat", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L778-L814
160,065
keybase/client
go/kbfs/libfs/fs.go
Symlink
func (fs *FS) Symlink(target, link string) (err error) { fs.log.CDebugf(fs.ctx, "Symlink target=%s link=%s", target, link) defer func() { fs.deferLog.CDebugf(fs.ctx, "Symlink done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } err = fs.ensureParentDir(link) if err != nil { return err } n, _, base, err := fs.lookupParent(link) if err != nil { return err } _, err = fs.config.KBFSOps().CreateLink(fs.ctx, n, base, target) return err }
go
func (fs *FS) Symlink(target, link string) (err error) { fs.log.CDebugf(fs.ctx, "Symlink target=%s link=%s", target, link) defer func() { fs.deferLog.CDebugf(fs.ctx, "Symlink done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } err = fs.ensureParentDir(link) if err != nil { return err } n, _, base, err := fs.lookupParent(link) if err != nil { return err } _, err = fs.config.KBFSOps().CreateLink(fs.ctx, n, base, target) return err }
[ "func", "(", "fs", "*", "FS", ")", "Symlink", "(", "target", ",", "link", "string", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "target", ",", "link", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "fs", ".", "ensureParentDir", "(", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "base", ",", "err", ":=", "fs", ".", "lookupParent", "(", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "CreateLink", "(", "fs", ".", "ctx", ",", "n", ",", "base", ",", "target", ")", "\n", "return", "err", "\n", "}" ]
// Symlink implements the billy.Filesystem interface for FS.
[ "Symlink", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L817-L840
160,066
keybase/client
go/kbfs/libfs/fs.go
Readlink
func (fs *FS) Readlink(link string) (target string, err error) { fs.log.CDebugf(fs.ctx, "Readlink %s", link) defer func() { fs.deferLog.CDebugf(fs.ctx, "Readlink done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return "", err } n, _, base, err := fs.lookupParent(link) if err != nil { return "", err } _, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, base) if err != nil { return "", err } if ei.Type != data.Sym { return "", errors.Errorf("%s is not a symlink", link) } return ei.SymPath, nil }
go
func (fs *FS) Readlink(link string) (target string, err error) { fs.log.CDebugf(fs.ctx, "Readlink %s", link) defer func() { fs.deferLog.CDebugf(fs.ctx, "Readlink done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return "", err } n, _, base, err := fs.lookupParent(link) if err != nil { return "", err } _, ei, err := fs.config.KBFSOps().Lookup(fs.ctx, n, base) if err != nil { return "", err } if ei.Type != data.Sym { return "", errors.Errorf("%s is not a symlink", link) } return ei.SymPath, nil }
[ "func", "(", "fs", "*", "FS", ")", "Readlink", "(", "link", "string", ")", "(", "target", "string", ",", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "link", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "base", ",", "err", ":=", "fs", ".", "lookupParent", "(", "link", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "_", ",", "ei", ",", "err", ":=", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Lookup", "(", "fs", ".", "ctx", ",", "n", ",", "base", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "ei", ".", "Type", "!=", "data", ".", "Sym", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "link", ")", "\n", "}", "\n", "return", "ei", ".", "SymPath", ",", "nil", "\n", "}" ]
// Readlink implements the billy.Filesystem interface for FS.
[ "Readlink", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L843-L868
160,067
keybase/client
go/kbfs/libfs/fs.go
Chmod
func (fs *FS) Chmod(name string, mode os.FileMode) (err error) { fs.log.CDebugf(fs.ctx, "Chmod %s %s", name, mode) defer func() { fs.deferLog.CDebugf(fs.ctx, "Chmod done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } n, _, err := fs.lookupOrCreateEntry(name, os.O_RDONLY, 0) if err != nil { return err } isExec := (mode & 0100) != 0 return fs.config.KBFSOps().SetEx(fs.ctx, n, isExec) }
go
func (fs *FS) Chmod(name string, mode os.FileMode) (err error) { fs.log.CDebugf(fs.ctx, "Chmod %s %s", name, mode) defer func() { fs.deferLog.CDebugf(fs.ctx, "Chmod done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } n, _, err := fs.lookupOrCreateEntry(name, os.O_RDONLY, 0) if err != nil { return err } isExec := (mode & 0100) != 0 return fs.config.KBFSOps().SetEx(fs.ctx, n, isExec) }
[ "func", "(", "fs", "*", "FS", ")", "Chmod", "(", "name", "string", ",", "mode", "os", ".", "FileMode", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "name", ",", "mode", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "err", ":=", "fs", ".", "lookupOrCreateEntry", "(", "name", ",", "os", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "isExec", ":=", "(", "mode", "&", "0100", ")", "!=", "0", "\n", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SetEx", "(", "fs", ".", "ctx", ",", "n", ",", "isExec", ")", "\n", "}" ]
// Chmod implements the billy.Filesystem interface for FS.
[ "Chmod", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L871-L889
160,068
keybase/client
go/kbfs/libfs/fs.go
Chown
func (fs *FS) Chown(name string, uid, gid int) error { // KBFS doesn't support ownership changes. fs.log.CDebugf(fs.ctx, "Ignoring Chown %s %d %d", name, uid, gid) return nil }
go
func (fs *FS) Chown(name string, uid, gid int) error { // KBFS doesn't support ownership changes. fs.log.CDebugf(fs.ctx, "Ignoring Chown %s %d %d", name, uid, gid) return nil }
[ "func", "(", "fs", "*", "FS", ")", "Chown", "(", "name", "string", ",", "uid", ",", "gid", "int", ")", "error", "{", "// KBFS doesn't support ownership changes.", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "name", ",", "uid", ",", "gid", ")", "\n", "return", "nil", "\n", "}" ]
// Chown implements the billy.Filesystem interface for FS.
[ "Chown", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L899-L903
160,069
keybase/client
go/kbfs/libfs/fs.go
Chtimes
func (fs *FS) Chtimes(name string, atime time.Time, mtime time.Time) ( err error) { fs.log.CDebugf(fs.ctx, "Chtimes %s mtime=%s; ignoring atime=%s", name, mtime, atime) defer func() { fs.deferLog.CDebugf(fs.ctx, "Chtimes done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } n, _, err := fs.lookupOrCreateEntry(name, os.O_RDONLY, 0) if err != nil { return err } return fs.config.KBFSOps().SetMtime(fs.ctx, n, &mtime) }
go
func (fs *FS) Chtimes(name string, atime time.Time, mtime time.Time) ( err error) { fs.log.CDebugf(fs.ctx, "Chtimes %s mtime=%s; ignoring atime=%s", name, mtime, atime) defer func() { fs.deferLog.CDebugf(fs.ctx, "Chtimes done: %+v", err) err = translateErr(err) }() if err := fs.requireNonEmpty(); err != nil { return err } n, _, err := fs.lookupOrCreateEntry(name, os.O_RDONLY, 0) if err != nil { return err } return fs.config.KBFSOps().SetMtime(fs.ctx, n, &mtime) }
[ "func", "(", "fs", "*", "FS", ")", "Chtimes", "(", "name", "string", ",", "atime", "time", ".", "Time", ",", "mtime", "time", ".", "Time", ")", "(", "err", "error", ")", "{", "fs", ".", "log", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "name", ",", "mtime", ",", "atime", ")", "\n", "defer", "func", "(", ")", "{", "fs", ".", "deferLog", ".", "CDebugf", "(", "fs", ".", "ctx", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "translateErr", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "n", ",", "_", ",", "err", ":=", "fs", ".", "lookupOrCreateEntry", "(", "name", ",", "os", ".", "O_RDONLY", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SetMtime", "(", "fs", ".", "ctx", ",", "n", ",", "&", "mtime", ")", "\n", "}" ]
// Chtimes implements the billy.Filesystem interface for FS.
[ "Chtimes", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L906-L925
160,070
keybase/client
go/kbfs/libfs/fs.go
Chroot
func (fs *FS) Chroot(p string) (newFS billy.Filesystem, err error) { return fs.ChrootAsLibFS(p) }
go
func (fs *FS) Chroot(p string) (newFS billy.Filesystem, err error) { return fs.ChrootAsLibFS(p) }
[ "func", "(", "fs", "*", "FS", ")", "Chroot", "(", "p", "string", ")", "(", "newFS", "billy", ".", "Filesystem", ",", "err", "error", ")", "{", "return", "fs", ".", "ChrootAsLibFS", "(", "p", ")", "\n", "}" ]
// Chroot implements the billy.Filesystem interface for FS.
[ "Chroot", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L973-L975
160,071
keybase/client
go/kbfs/libfs/fs.go
Root
func (fs *FS) Root() string { return path.Join(fs.h.GetCanonicalPath(), fs.subdir) }
go
func (fs *FS) Root() string { return path.Join(fs.h.GetCanonicalPath(), fs.subdir) }
[ "func", "(", "fs", "*", "FS", ")", "Root", "(", ")", "string", "{", "return", "path", ".", "Join", "(", "fs", ".", "h", ".", "GetCanonicalPath", "(", ")", ",", "fs", ".", "subdir", ")", "\n", "}" ]
// Root implements the billy.Filesystem interface for FS.
[ "Root", "implements", "the", "billy", ".", "Filesystem", "interface", "for", "FS", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L978-L980
160,072
keybase/client
go/kbfs/libfs/fs.go
SyncAll
func (fs *FS) SyncAll() error { if err := fs.requireNonEmpty(); err != nil { return err } return fs.config.KBFSOps().SyncAll(fs.ctx, fs.root.GetFolderBranch()) }
go
func (fs *FS) SyncAll() error { if err := fs.requireNonEmpty(); err != nil { return err } return fs.config.KBFSOps().SyncAll(fs.ctx, fs.root.GetFolderBranch()) }
[ "func", "(", "fs", "*", "FS", ")", "SyncAll", "(", ")", "error", "{", "if", "err", ":=", "fs", ".", "requireNonEmpty", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SyncAll", "(", "fs", ".", "ctx", ",", "fs", ".", "root", ".", "GetFolderBranch", "(", ")", ")", "\n", "}" ]
// SyncAll syncs any outstanding buffered writes to the KBFS journal.
[ "SyncAll", "syncs", "any", "outstanding", "buffered", "writes", "to", "the", "KBFS", "journal", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L983-L988
160,073
keybase/client
go/kbfs/libfs/fs.go
SetLockNamespace
func (fs *FS) SetLockNamespace(lockNamespace []byte) { fs.lockNamespace = make([]byte, len(lockNamespace)) copy(fs.lockNamespace, lockNamespace) }
go
func (fs *FS) SetLockNamespace(lockNamespace []byte) { fs.lockNamespace = make([]byte, len(lockNamespace)) copy(fs.lockNamespace, lockNamespace) }
[ "func", "(", "fs", "*", "FS", ")", "SetLockNamespace", "(", "lockNamespace", "[", "]", "byte", ")", "{", "fs", ".", "lockNamespace", "=", "make", "(", "[", "]", "byte", ",", "len", "(", "lockNamespace", ")", ")", "\n", "copy", "(", "fs", ".", "lockNamespace", ",", "lockNamespace", ")", "\n", "}" ]
// SetLockNamespace sets the namespace used in locking.
[ "SetLockNamespace", "sets", "the", "namespace", "used", "in", "locking", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/fs.go#L996-L999
160,074
keybase/client
go/protocol/keybase1/rekey.go
ShowPendingRekeyStatus
func (c RekeyClient) ShowPendingRekeyStatus(ctx context.Context, sessionID int) (err error) { __arg := ShowPendingRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.showPendingRekeyStatus", []interface{}{__arg}, nil) return }
go
func (c RekeyClient) ShowPendingRekeyStatus(ctx context.Context, sessionID int) (err error) { __arg := ShowPendingRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.showPendingRekeyStatus", []interface{}{__arg}, nil) return }
[ "func", "(", "c", "RekeyClient", ")", "ShowPendingRekeyStatus", "(", "ctx", "context", ".", "Context", ",", "sessionID", "int", ")", "(", "err", "error", ")", "{", "__arg", ":=", "ShowPendingRekeyStatusArg", "{", "SessionID", ":", "sessionID", "}", "\n", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ")", "\n", "return", "\n", "}" ]
// ShowPendingRekeyStatus shows either pending gregor-initiated rekey harassments // or nothing if none were pending.
[ "ShowPendingRekeyStatus", "shows", "either", "pending", "gregor", "-", "initiated", "rekey", "harassments", "or", "nothing", "if", "none", "were", "pending", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L324-L328
160,075
keybase/client
go/protocol/keybase1/rekey.go
GetPendingRekeyStatus
func (c RekeyClient) GetPendingRekeyStatus(ctx context.Context, sessionID int) (res ProblemSetDevices, err error) { __arg := GetPendingRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.getPendingRekeyStatus", []interface{}{__arg}, &res) return }
go
func (c RekeyClient) GetPendingRekeyStatus(ctx context.Context, sessionID int) (res ProblemSetDevices, err error) { __arg := GetPendingRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.getPendingRekeyStatus", []interface{}{__arg}, &res) return }
[ "func", "(", "c", "RekeyClient", ")", "GetPendingRekeyStatus", "(", "ctx", "context", ".", "Context", ",", "sessionID", "int", ")", "(", "res", "ProblemSetDevices", ",", "err", "error", ")", "{", "__arg", ":=", "GetPendingRekeyStatusArg", "{", "SessionID", ":", "sessionID", "}", "\n", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "&", "res", ")", "\n", "return", "\n", "}" ]
// GetPendingRekeyStatus returns the pending ProblemSetDevices.
[ "GetPendingRekeyStatus", "returns", "the", "pending", "ProblemSetDevices", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L331-L335
160,076
keybase/client
go/protocol/keybase1/rekey.go
DebugShowRekeyStatus
func (c RekeyClient) DebugShowRekeyStatus(ctx context.Context, sessionID int) (err error) { __arg := DebugShowRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.debugShowRekeyStatus", []interface{}{__arg}, nil) return }
go
func (c RekeyClient) DebugShowRekeyStatus(ctx context.Context, sessionID int) (err error) { __arg := DebugShowRekeyStatusArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.debugShowRekeyStatus", []interface{}{__arg}, nil) return }
[ "func", "(", "c", "RekeyClient", ")", "DebugShowRekeyStatus", "(", "ctx", "context", ".", "Context", ",", "sessionID", "int", ")", "(", "err", "error", ")", "{", "__arg", ":=", "DebugShowRekeyStatusArg", "{", "SessionID", ":", "sessionID", "}", "\n", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ")", "\n", "return", "\n", "}" ]
// DebugShowRekeyStatus is used by the CLI to kick off a "ShowRekeyStatus" window for // the current user.
[ "DebugShowRekeyStatus", "is", "used", "by", "the", "CLI", "to", "kick", "off", "a", "ShowRekeyStatus", "window", "for", "the", "current", "user", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L339-L343
160,077
keybase/client
go/protocol/keybase1/rekey.go
RekeyStatusFinish
func (c RekeyClient) RekeyStatusFinish(ctx context.Context, sessionID int) (res Outcome, err error) { __arg := RekeyStatusFinishArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.rekeyStatusFinish", []interface{}{__arg}, &res) return }
go
func (c RekeyClient) RekeyStatusFinish(ctx context.Context, sessionID int) (res Outcome, err error) { __arg := RekeyStatusFinishArg{SessionID: sessionID} err = c.Cli.Call(ctx, "keybase.1.rekey.rekeyStatusFinish", []interface{}{__arg}, &res) return }
[ "func", "(", "c", "RekeyClient", ")", "RekeyStatusFinish", "(", "ctx", "context", ".", "Context", ",", "sessionID", "int", ")", "(", "res", "Outcome", ",", "err", "error", ")", "{", "__arg", ":=", "RekeyStatusFinishArg", "{", "SessionID", ":", "sessionID", "}", "\n", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "&", "res", ")", "\n", "return", "\n", "}" ]
// RekeyStatusFinish is called when work is completed on a given RekeyStatus window. The Outcome // can be Fixed or Ignored.
[ "RekeyStatusFinish", "is", "called", "when", "work", "is", "completed", "on", "a", "given", "RekeyStatus", "window", ".", "The", "Outcome", "can", "be", "Fixed", "or", "Ignored", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L347-L351
160,078
keybase/client
go/protocol/keybase1/rekey.go
RekeySync
func (c RekeyClient) RekeySync(ctx context.Context, __arg RekeySyncArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.rekey.rekeySync", []interface{}{__arg}, nil) return }
go
func (c RekeyClient) RekeySync(ctx context.Context, __arg RekeySyncArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.rekey.rekeySync", []interface{}{__arg}, nil) return }
[ "func", "(", "c", "RekeyClient", ")", "RekeySync", "(", "ctx", "context", ".", "Context", ",", "__arg", "RekeySyncArg", ")", "(", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ")", "\n", "return", "\n", "}" ]
// RekeySync flushes the current rekey loop and gets to a good stopping point // to assert state. Good for race-free testing, not very useful in production. // Force overrides a long-snooze.
[ "RekeySync", "flushes", "the", "current", "rekey", "loop", "and", "gets", "to", "a", "good", "stopping", "point", "to", "assert", "state", ".", "Good", "for", "race", "-", "free", "testing", "not", "very", "useful", "in", "production", ".", "Force", "overrides", "a", "long", "-", "snooze", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L356-L359
160,079
keybase/client
go/protocol/keybase1/rekey.go
GetRevokeWarning
func (c RekeyClient) GetRevokeWarning(ctx context.Context, __arg GetRevokeWarningArg) (res RevokeWarning, err error) { err = c.Cli.Call(ctx, "keybase.1.rekey.getRevokeWarning", []interface{}{__arg}, &res) return }
go
func (c RekeyClient) GetRevokeWarning(ctx context.Context, __arg GetRevokeWarningArg) (res RevokeWarning, err error) { err = c.Cli.Call(ctx, "keybase.1.rekey.getRevokeWarning", []interface{}{__arg}, &res) return }
[ "func", "(", "c", "RekeyClient", ")", "GetRevokeWarning", "(", "ctx", "context", ".", "Context", ",", "__arg", "GetRevokeWarningArg", ")", "(", "res", "RevokeWarning", ",", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "&", "res", ")", "\n", "return", "\n", "}" ]
// GetRevokeWarning computes the TLFs that will be endangered if actingDevice // revokes targetDevice.
[ "GetRevokeWarning", "computes", "the", "TLFs", "that", "will", "be", "endangered", "if", "actingDevice", "revokes", "targetDevice", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey.go#L363-L366
160,080
keybase/client
go/install/winversion.go
FileVersion
func (fi VS_FIXEDFILEINFO) FileVersion() uint64 { return uint64(fi.FileVersionMS)<<32 | uint64(fi.FileVersionLS) }
go
func (fi VS_FIXEDFILEINFO) FileVersion() uint64 { return uint64(fi.FileVersionMS)<<32 | uint64(fi.FileVersionLS) }
[ "func", "(", "fi", "VS_FIXEDFILEINFO", ")", "FileVersion", "(", ")", "uint64", "{", "return", "uint64", "(", "fi", ".", "FileVersionMS", ")", "<<", "32", "|", "uint64", "(", "fi", ".", "FileVersionLS", ")", "\n", "}" ]
// FileVersion concatenates FileVersionMS and FileVersionLS to a uint64 value.
[ "FileVersion", "concatenates", "FileVersionMS", "and", "FileVersionLS", "to", "a", "uint64", "value", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/install/winversion.go#L49-L51
160,081
keybase/client
go/protocol/keybase1/selfprovision.go
SelfProvision
func (c SelfprovisionClient) SelfProvision(ctx context.Context, __arg SelfProvisionArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.selfprovision.selfProvision", []interface{}{__arg}, nil) return }
go
func (c SelfprovisionClient) SelfProvision(ctx context.Context, __arg SelfProvisionArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.selfprovision.selfProvision", []interface{}{__arg}, nil) return }
[ "func", "(", "c", "SelfprovisionClient", ")", "SelfProvision", "(", "ctx", "context", ".", "Context", ",", "__arg", "SelfProvisionArg", ")", "(", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ")", "\n", "return", "\n", "}" ]
// Performs self provision. If the current device is clone, this function // will provision it as a new device.
[ "Performs", "self", "provision", ".", "If", "the", "current", "device", "is", "clone", "this", "function", "will", "provision", "it", "as", "a", "new", "device", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/selfprovision.go#L51-L54
160,082
keybase/client
go/logger/standard.go
LogTagsFromContext
func LogTagsFromContext(ctx context.Context) (CtxLogTags, bool) { logTags, ok := ctx.Value(CtxLogTagsKey).(CtxLogTags) return logTags, ok }
go
func LogTagsFromContext(ctx context.Context) (CtxLogTags, bool) { logTags, ok := ctx.Value(CtxLogTagsKey).(CtxLogTags) return logTags, ok }
[ "func", "LogTagsFromContext", "(", "ctx", "context", ".", "Context", ")", "(", "CtxLogTags", ",", "bool", ")", "{", "logTags", ",", "ok", ":=", "ctx", ".", "Value", "(", "CtxLogTagsKey", ")", ".", "(", "CtxLogTags", ")", "\n", "return", "logTags", ",", "ok", "\n", "}" ]
// LogTagsFromContext returns the log tags being passed along with the // given context.
[ "LogTagsFromContext", "returns", "the", "log", "tags", "being", "passed", "along", "with", "the", "given", "context", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/logger/standard.go#L62-L65
160,083
keybase/client
go/logger/standard.go
ConvertRPCTagsToLogTags
func ConvertRPCTagsToLogTags(ctx context.Context) context.Context { rpcTags, ok := rpc.RpcTagsFromContext(ctx) if !ok { return ctx } tags := make(CtxLogTags) for key, value := range rpcTags { // The map key should be a proper unique type, but that's not // passed along in the RPC so just use our own string-like type. tags[rpcTagKey(key)] = key ctx = context.WithValue(ctx, rpcTagKey(key), value) } ctx = context.WithValue(ctx, rpc.CtxRpcTagsKey, nil) return NewContextWithLogTags(ctx, tags) }
go
func ConvertRPCTagsToLogTags(ctx context.Context) context.Context { rpcTags, ok := rpc.RpcTagsFromContext(ctx) if !ok { return ctx } tags := make(CtxLogTags) for key, value := range rpcTags { // The map key should be a proper unique type, but that's not // passed along in the RPC so just use our own string-like type. tags[rpcTagKey(key)] = key ctx = context.WithValue(ctx, rpcTagKey(key), value) } ctx = context.WithValue(ctx, rpc.CtxRpcTagsKey, nil) return NewContextWithLogTags(ctx, tags) }
[ "func", "ConvertRPCTagsToLogTags", "(", "ctx", "context", ".", "Context", ")", "context", ".", "Context", "{", "rpcTags", ",", "ok", ":=", "rpc", ".", "RpcTagsFromContext", "(", "ctx", ")", "\n", "if", "!", "ok", "{", "return", "ctx", "\n", "}", "\n\n", "tags", ":=", "make", "(", "CtxLogTags", ")", "\n", "for", "key", ",", "value", ":=", "range", "rpcTags", "{", "// The map key should be a proper unique type, but that's not", "// passed along in the RPC so just use our own string-like type.", "tags", "[", "rpcTagKey", "(", "key", ")", "]", "=", "key", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "rpcTagKey", "(", "key", ")", ",", "value", ")", "\n", "}", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "rpc", ".", "CtxRpcTagsKey", ",", "nil", ")", "\n", "return", "NewContextWithLogTags", "(", "ctx", ",", "tags", ")", "\n", "}" ]
// ConvertRPCTagsToLogTags takes any RPC tags in the context and makes // them log tags. It uses the string representation of the tag key, // rather than the original uniquely typed key, since the latter isn't // available in the RPC tags.
[ "ConvertRPCTagsToLogTags", "takes", "any", "RPC", "tags", "in", "the", "context", "and", "makes", "them", "log", "tags", ".", "It", "uses", "the", "string", "representation", "of", "the", "tag", "key", "rather", "than", "the", "original", "uniquely", "typed", "key", "since", "the", "latter", "isn", "t", "available", "in", "the", "RPC", "tags", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/logger/standard.go#L81-L96
160,084
keybase/client
go/logger/standard.go
NewWithCallDepth
func NewWithCallDepth(module string, extraCallDepth int) *Standard { log := logging.MustGetLogger(module) log.ExtraCalldepth = 1 + extraCallDepth ret := &Standard{ internal: log, module: module, } ret.setLogLevelInfo() return ret }
go
func NewWithCallDepth(module string, extraCallDepth int) *Standard { log := logging.MustGetLogger(module) log.ExtraCalldepth = 1 + extraCallDepth ret := &Standard{ internal: log, module: module, } ret.setLogLevelInfo() return ret }
[ "func", "NewWithCallDepth", "(", "module", "string", ",", "extraCallDepth", "int", ")", "*", "Standard", "{", "log", ":=", "logging", ".", "MustGetLogger", "(", "module", ")", "\n", "log", ".", "ExtraCalldepth", "=", "1", "+", "extraCallDepth", "\n\n", "ret", ":=", "&", "Standard", "{", "internal", ":", "log", ",", "module", ":", "module", ",", "}", "\n", "ret", ".", "setLogLevelInfo", "(", ")", "\n", "return", "ret", "\n", "}" ]
// NewWithCallDepth creates a new Standard logger for module, and when // printing file names and line numbers, it goes extraCallDepth up the // stack from where logger was invoked.
[ "NewWithCallDepth", "creates", "a", "new", "Standard", "logger", "for", "module", "and", "when", "printing", "file", "names", "and", "line", "numbers", "it", "goes", "extraCallDepth", "up", "the", "stack", "from", "where", "logger", "was", "invoked", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/logger/standard.go#L128-L138
160,085
keybase/client
go/libkb/log_send.go
tail
func tail(log logger.Logger, which string, stem string, numBytes int) (ret string) { numFiles := 0 log.Debug("+ tailing %s file with stem %q", which, stem) defer func() { log.Debug("- collected %d bytes from %d files", len(ret), numFiles) }() if len(stem) == 0 { log.Debug("| skipping %s logs (since no stem given)", which) return } lognames := listLogFiles(log, stem) var parts []string remaining := numBytes // Keep reading logs in reverse chronological order until we've read nothing // more, or we've filled up numBytes worth of buffer, or we didn't have to read // the whole file. for _, logname := range lognames { data, seeked := tailFile(log, which, logname, remaining) if len(data) == 0 { break } parts = append(parts, data) numFiles++ remaining -= len(data) if remaining <= 0 || seeked { break } } // Reverse the array; took this one-line from StackOverflow answer for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 { parts[i], parts[j] = parts[j], parts[i] } return strings.Join(parts, "") }
go
func tail(log logger.Logger, which string, stem string, numBytes int) (ret string) { numFiles := 0 log.Debug("+ tailing %s file with stem %q", which, stem) defer func() { log.Debug("- collected %d bytes from %d files", len(ret), numFiles) }() if len(stem) == 0 { log.Debug("| skipping %s logs (since no stem given)", which) return } lognames := listLogFiles(log, stem) var parts []string remaining := numBytes // Keep reading logs in reverse chronological order until we've read nothing // more, or we've filled up numBytes worth of buffer, or we didn't have to read // the whole file. for _, logname := range lognames { data, seeked := tailFile(log, which, logname, remaining) if len(data) == 0 { break } parts = append(parts, data) numFiles++ remaining -= len(data) if remaining <= 0 || seeked { break } } // Reverse the array; took this one-line from StackOverflow answer for i, j := 0, len(parts)-1; i < j; i, j = i+1, j-1 { parts[i], parts[j] = parts[j], parts[i] } return strings.Join(parts, "") }
[ "func", "tail", "(", "log", "logger", ".", "Logger", ",", "which", "string", ",", "stem", "string", ",", "numBytes", "int", ")", "(", "ret", "string", ")", "{", "numFiles", ":=", "0", "\n\n", "log", ".", "Debug", "(", "\"", "\"", ",", "which", ",", "stem", ")", "\n", "defer", "func", "(", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "len", "(", "ret", ")", ",", "numFiles", ")", "\n", "}", "(", ")", "\n\n", "if", "len", "(", "stem", ")", "==", "0", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "which", ")", "\n", "return", "\n", "}", "\n\n", "lognames", ":=", "listLogFiles", "(", "log", ",", "stem", ")", "\n", "var", "parts", "[", "]", "string", "\n", "remaining", ":=", "numBytes", "\n\n", "// Keep reading logs in reverse chronological order until we've read nothing", "// more, or we've filled up numBytes worth of buffer, or we didn't have to read", "// the whole file.", "for", "_", ",", "logname", ":=", "range", "lognames", "{", "data", ",", "seeked", ":=", "tailFile", "(", "log", ",", "which", ",", "logname", ",", "remaining", ")", "\n", "if", "len", "(", "data", ")", "==", "0", "{", "break", "\n", "}", "\n", "parts", "=", "append", "(", "parts", ",", "data", ")", "\n", "numFiles", "++", "\n", "remaining", "-=", "len", "(", "data", ")", "\n", "if", "remaining", "<=", "0", "||", "seeked", "{", "break", "\n", "}", "\n", "}", "\n\n", "// Reverse the array; took this one-line from StackOverflow answer", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "parts", ")", "-", "1", ";", "i", "<", "j", ";", "i", ",", "j", "=", "i", "+", "1", ",", "j", "-", "1", "{", "parts", "[", "i", "]", ",", "parts", "[", "j", "]", "=", "parts", "[", "j", "]", ",", "parts", "[", "i", "]", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "parts", ",", "\"", "\"", ")", "\n", "}" ]
// tail the logs that start with the stem `stem`, which are of type `which`. // Get the most recent `numBytes` from the concatenation of the files.
[ "tail", "the", "logs", "that", "start", "with", "the", "stem", "stem", "which", "are", "of", "type", "which", ".", "Get", "the", "most", "recent", "numBytes", "from", "the", "concatenation", "of", "the", "files", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/log_send.go#L177-L217
160,086
keybase/client
go/libkb/log_send.go
findFirstNewline
func findFirstNewline(b []byte) []byte { index := bytes.IndexByte(b, '\n') if index < 0 || index == len(b)-1 { return nil } return b[(index + 1):] }
go
func findFirstNewline(b []byte) []byte { index := bytes.IndexByte(b, '\n') if index < 0 || index == len(b)-1 { return nil } return b[(index + 1):] }
[ "func", "findFirstNewline", "(", "b", "[", "]", "byte", ")", "[", "]", "byte", "{", "index", ":=", "bytes", ".", "IndexByte", "(", "b", ",", "'\\n'", ")", "\n", "if", "index", "<", "0", "||", "index", "==", "len", "(", "b", ")", "-", "1", "{", "return", "nil", "\n", "}", "\n", "return", "b", "[", "(", "index", "+", "1", ")", ":", "]", "\n", "}" ]
// findFirstNewline first the first newline in the given byte array, and then returns the // rest of the byte array. Should be safe to use on utf-8 strings.
[ "findFirstNewline", "first", "the", "first", "newline", "in", "the", "given", "byte", "array", "and", "then", "returns", "the", "rest", "of", "the", "byte", "array", ".", "Should", "be", "safe", "to", "use", "on", "utf", "-", "8", "strings", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/log_send.go#L288-L294
160,087
keybase/client
go/libkb/log_send.go
tailSystemdJournal
func tailSystemdJournal(log logger.Logger, userUnits []string, numBytes int) (ret string) { log.Debug("+ tailing journalctl for %#v (%d bytes)", userUnits, numBytes) defer func() { log.Debug("- scanned %d bytes", len(ret)) }() // Journalctl doesn't provide a "last N bytes" flag directly, so instead we // use "last N lines". Large log files in practice seem to be about 150 // bits per line. We'll request lines on that assumption, but if we get // more than 2x as many bytes as we expected, we'll stop reading and // include a big error. guessedLines := numBytes / 150 maxBytes := numBytes * 2 // We intentionally avoid the --user flag to journalctl. That would make us // skip over the system journal, but in e.g. Ubuntu 16.04, that's where // user units write their logs. // Unfortunately, this causes permission errors in some operating systems // like Debian Stretch, but it is not fatal. as we ignore errors in this // function. args := []string{ "--lines=" + strconv.Itoa(guessedLines), } if len(userUnits) == 0 { panic("without --user-unit we would scrape all system logs!!!") } for _, userUnit := range userUnits { args = append(args, "--user-unit="+userUnit) } journalCmd := exec.Command("journalctl", args...) journalCmd.Stderr = os.Stderr stdout, err := journalCmd.StdoutPipe() if err != nil { msg := fmt.Sprintf("Failed to open a pipe for journalctl: %s", err) log.Errorf(msg) return msg } err = journalCmd.Start() if err != nil { msg := fmt.Sprintf("Failed to run journalctl: %s", err) log.Errorf(msg) return msg } // Once we start reading output, don't short-circuit on errors. Just log // them, and return whatever we got. stdoutLimited := io.LimitReader(stdout, int64(maxBytes)) output, err := ioutil.ReadAll(stdoutLimited) if err != nil { output = appendError(log, output, "Error reading from journalctl pipe: %s", err) } // We must close stdout before Wait, or else Wait might deadlock. stdout.Close() err = journalCmd.Wait() if err != nil { output = appendError(log, output, "Journalctl exited with an error: %s", err) } if len(output) >= maxBytes { output = appendError(log, output, "Journal lines longer than expected. Logs truncated.") } return string(output) }
go
func tailSystemdJournal(log logger.Logger, userUnits []string, numBytes int) (ret string) { log.Debug("+ tailing journalctl for %#v (%d bytes)", userUnits, numBytes) defer func() { log.Debug("- scanned %d bytes", len(ret)) }() // Journalctl doesn't provide a "last N bytes" flag directly, so instead we // use "last N lines". Large log files in practice seem to be about 150 // bits per line. We'll request lines on that assumption, but if we get // more than 2x as many bytes as we expected, we'll stop reading and // include a big error. guessedLines := numBytes / 150 maxBytes := numBytes * 2 // We intentionally avoid the --user flag to journalctl. That would make us // skip over the system journal, but in e.g. Ubuntu 16.04, that's where // user units write their logs. // Unfortunately, this causes permission errors in some operating systems // like Debian Stretch, but it is not fatal. as we ignore errors in this // function. args := []string{ "--lines=" + strconv.Itoa(guessedLines), } if len(userUnits) == 0 { panic("without --user-unit we would scrape all system logs!!!") } for _, userUnit := range userUnits { args = append(args, "--user-unit="+userUnit) } journalCmd := exec.Command("journalctl", args...) journalCmd.Stderr = os.Stderr stdout, err := journalCmd.StdoutPipe() if err != nil { msg := fmt.Sprintf("Failed to open a pipe for journalctl: %s", err) log.Errorf(msg) return msg } err = journalCmd.Start() if err != nil { msg := fmt.Sprintf("Failed to run journalctl: %s", err) log.Errorf(msg) return msg } // Once we start reading output, don't short-circuit on errors. Just log // them, and return whatever we got. stdoutLimited := io.LimitReader(stdout, int64(maxBytes)) output, err := ioutil.ReadAll(stdoutLimited) if err != nil { output = appendError(log, output, "Error reading from journalctl pipe: %s", err) } // We must close stdout before Wait, or else Wait might deadlock. stdout.Close() err = journalCmd.Wait() if err != nil { output = appendError(log, output, "Journalctl exited with an error: %s", err) } if len(output) >= maxBytes { output = appendError(log, output, "Journal lines longer than expected. Logs truncated.") } return string(output) }
[ "func", "tailSystemdJournal", "(", "log", "logger", ".", "Logger", ",", "userUnits", "[", "]", "string", ",", "numBytes", "int", ")", "(", "ret", "string", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "userUnits", ",", "numBytes", ")", "\n", "defer", "func", "(", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "len", "(", "ret", ")", ")", "\n", "}", "(", ")", "\n\n", "// Journalctl doesn't provide a \"last N bytes\" flag directly, so instead we", "// use \"last N lines\". Large log files in practice seem to be about 150", "// bits per line. We'll request lines on that assumption, but if we get", "// more than 2x as many bytes as we expected, we'll stop reading and", "// include a big error.", "guessedLines", ":=", "numBytes", "/", "150", "\n", "maxBytes", ":=", "numBytes", "*", "2", "\n\n", "// We intentionally avoid the --user flag to journalctl. That would make us", "// skip over the system journal, but in e.g. Ubuntu 16.04, that's where", "// user units write their logs.", "// Unfortunately, this causes permission errors in some operating systems", "// like Debian Stretch, but it is not fatal. as we ignore errors in this", "// function.", "args", ":=", "[", "]", "string", "{", "\"", "\"", "+", "strconv", ".", "Itoa", "(", "guessedLines", ")", ",", "}", "\n", "if", "len", "(", "userUnits", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "userUnit", ":=", "range", "userUnits", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", "+", "userUnit", ")", "\n", "}", "\n", "journalCmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "args", "...", ")", "\n", "journalCmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "stdout", ",", "err", ":=", "journalCmd", ".", "StdoutPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "\n", "log", ".", "Errorf", "(", "msg", ")", "\n", "return", "msg", "\n", "}", "\n", "err", "=", "journalCmd", ".", "Start", "(", ")", "\n", "if", "err", "!=", "nil", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", "\n", "log", ".", "Errorf", "(", "msg", ")", "\n", "return", "msg", "\n", "}", "\n\n", "// Once we start reading output, don't short-circuit on errors. Just log", "// them, and return whatever we got.", "stdoutLimited", ":=", "io", ".", "LimitReader", "(", "stdout", ",", "int64", "(", "maxBytes", ")", ")", "\n", "output", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "stdoutLimited", ")", "\n", "if", "err", "!=", "nil", "{", "output", "=", "appendError", "(", "log", ",", "output", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "// We must close stdout before Wait, or else Wait might deadlock.", "stdout", ".", "Close", "(", ")", "\n", "err", "=", "journalCmd", ".", "Wait", "(", ")", "\n", "if", "err", "!=", "nil", "{", "output", "=", "appendError", "(", "log", ",", "output", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "len", "(", "output", ")", ">=", "maxBytes", "{", "output", "=", "appendError", "(", "log", ",", "output", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "string", "(", "output", ")", "\n", "}" ]
// Get logs from the systemd journal. Currently we don't use this for most of // our logging, since it's not persisted across boot on some systems. But we do // use it for startup logs.
[ "Get", "logs", "from", "the", "systemd", "journal", ".", "Currently", "we", "don", "t", "use", "this", "for", "most", "of", "our", "logging", "since", "it", "s", "not", "persisted", "across", "boot", "on", "some", "systems", ".", "But", "we", "do", "use", "it", "for", "startup", "logs", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/log_send.go#L305-L366
160,088
keybase/client
go/libkb/log_send.go
LogSend
func (l *LogSendContext) LogSend(statusJSON, feedback string, sendLogs bool, numBytes int, uid keybase1.UID, installID InstallID, mergeExtendedStatus bool) (string, error) { mctx := NewMetaContextBackground(l.G()).WithLogTag("LOGSEND") logs := l.Logs var kbfsLog string var svcLog string var ekLog string var desktopLog string var updaterLog string var startLog string var installLog string var systemLog string var gitLog string var traceBundle []byte var cpuProfileBundle []byte var watchdogLog string var processesLog string if sendLogs { svcLog = tail(l.G().Log, "service", logs.Service, numBytes) ekLog = tail(l.G().Log, "ek", logs.EK, numBytes) kbfsLog = tail(l.G().Log, "kbfs", logs.Kbfs, numBytes) desktopLog = tail(l.G().Log, "desktop", logs.Desktop, numBytes) updaterLog = tail(l.G().Log, "updater", logs.Updater, numBytes) // We don't use the systemd journal to store regular logs, since on // some systems (e.g. Ubuntu 16.04) it's not persisted across boots. // However we do use it for startup logs, since that's the only place // to get them in systemd mode. if l.G().Env.WantsSystemd() { startLog = tailSystemdJournal(l.G().Log, []string{"keybase.service", "keybase.ek", "kbfs.service", "keybase.gui.service", "keybase-redirector.service"}, numBytes) } else { startLog = tail(l.G().Log, "start", logs.Start, numBytes) } installLog = tail(l.G().Log, "install", logs.Install, numBytes) systemLog = tail(l.G().Log, "system", logs.System, numBytes) gitLog = tail(l.G().Log, "git", logs.Git, numBytes) watchdogLog = tail(l.G().Log, "watchdog", logs.Watchdog, numBytes) if logs.Trace != "" { traceBundle = getTraceBundle(l.G().Log, logs.Trace) } if logs.CPUProfile != "" { cpuProfileBundle = getCPUProfileBundle(l.G().Log, logs.CPUProfile) } // Only add extended status if we're sending logs if mergeExtendedStatus { statusJSON = l.mergeExtendedStatus(statusJSON) } processesLog = keybaseProcessList() } return l.post(mctx, statusJSON, feedback, kbfsLog, svcLog, ekLog, desktopLog, updaterLog, startLog, installLog, systemLog, gitLog, watchdogLog, traceBundle, cpuProfileBundle, uid, installID, processesLog) }
go
func (l *LogSendContext) LogSend(statusJSON, feedback string, sendLogs bool, numBytes int, uid keybase1.UID, installID InstallID, mergeExtendedStatus bool) (string, error) { mctx := NewMetaContextBackground(l.G()).WithLogTag("LOGSEND") logs := l.Logs var kbfsLog string var svcLog string var ekLog string var desktopLog string var updaterLog string var startLog string var installLog string var systemLog string var gitLog string var traceBundle []byte var cpuProfileBundle []byte var watchdogLog string var processesLog string if sendLogs { svcLog = tail(l.G().Log, "service", logs.Service, numBytes) ekLog = tail(l.G().Log, "ek", logs.EK, numBytes) kbfsLog = tail(l.G().Log, "kbfs", logs.Kbfs, numBytes) desktopLog = tail(l.G().Log, "desktop", logs.Desktop, numBytes) updaterLog = tail(l.G().Log, "updater", logs.Updater, numBytes) // We don't use the systemd journal to store regular logs, since on // some systems (e.g. Ubuntu 16.04) it's not persisted across boots. // However we do use it for startup logs, since that's the only place // to get them in systemd mode. if l.G().Env.WantsSystemd() { startLog = tailSystemdJournal(l.G().Log, []string{"keybase.service", "keybase.ek", "kbfs.service", "keybase.gui.service", "keybase-redirector.service"}, numBytes) } else { startLog = tail(l.G().Log, "start", logs.Start, numBytes) } installLog = tail(l.G().Log, "install", logs.Install, numBytes) systemLog = tail(l.G().Log, "system", logs.System, numBytes) gitLog = tail(l.G().Log, "git", logs.Git, numBytes) watchdogLog = tail(l.G().Log, "watchdog", logs.Watchdog, numBytes) if logs.Trace != "" { traceBundle = getTraceBundle(l.G().Log, logs.Trace) } if logs.CPUProfile != "" { cpuProfileBundle = getCPUProfileBundle(l.G().Log, logs.CPUProfile) } // Only add extended status if we're sending logs if mergeExtendedStatus { statusJSON = l.mergeExtendedStatus(statusJSON) } processesLog = keybaseProcessList() } return l.post(mctx, statusJSON, feedback, kbfsLog, svcLog, ekLog, desktopLog, updaterLog, startLog, installLog, systemLog, gitLog, watchdogLog, traceBundle, cpuProfileBundle, uid, installID, processesLog) }
[ "func", "(", "l", "*", "LogSendContext", ")", "LogSend", "(", "statusJSON", ",", "feedback", "string", ",", "sendLogs", "bool", ",", "numBytes", "int", ",", "uid", "keybase1", ".", "UID", ",", "installID", "InstallID", ",", "mergeExtendedStatus", "bool", ")", "(", "string", ",", "error", ")", "{", "mctx", ":=", "NewMetaContextBackground", "(", "l", ".", "G", "(", ")", ")", ".", "WithLogTag", "(", "\"", "\"", ")", "\n", "logs", ":=", "l", ".", "Logs", "\n", "var", "kbfsLog", "string", "\n", "var", "svcLog", "string", "\n", "var", "ekLog", "string", "\n", "var", "desktopLog", "string", "\n", "var", "updaterLog", "string", "\n", "var", "startLog", "string", "\n", "var", "installLog", "string", "\n", "var", "systemLog", "string", "\n", "var", "gitLog", "string", "\n", "var", "traceBundle", "[", "]", "byte", "\n", "var", "cpuProfileBundle", "[", "]", "byte", "\n", "var", "watchdogLog", "string", "\n", "var", "processesLog", "string", "\n\n", "if", "sendLogs", "{", "svcLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Service", ",", "numBytes", ")", "\n", "ekLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "EK", ",", "numBytes", ")", "\n", "kbfsLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Kbfs", ",", "numBytes", ")", "\n", "desktopLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Desktop", ",", "numBytes", ")", "\n", "updaterLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Updater", ",", "numBytes", ")", "\n", "// We don't use the systemd journal to store regular logs, since on", "// some systems (e.g. Ubuntu 16.04) it's not persisted across boots.", "// However we do use it for startup logs, since that's the only place", "// to get them in systemd mode.", "if", "l", ".", "G", "(", ")", ".", "Env", ".", "WantsSystemd", "(", ")", "{", "startLog", "=", "tailSystemdJournal", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", ",", "numBytes", ")", "\n", "}", "else", "{", "startLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Start", ",", "numBytes", ")", "\n", "}", "\n", "installLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Install", ",", "numBytes", ")", "\n", "systemLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "System", ",", "numBytes", ")", "\n", "gitLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Git", ",", "numBytes", ")", "\n", "watchdogLog", "=", "tail", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "\"", "\"", ",", "logs", ".", "Watchdog", ",", "numBytes", ")", "\n", "if", "logs", ".", "Trace", "!=", "\"", "\"", "{", "traceBundle", "=", "getTraceBundle", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "logs", ".", "Trace", ")", "\n", "}", "\n", "if", "logs", ".", "CPUProfile", "!=", "\"", "\"", "{", "cpuProfileBundle", "=", "getCPUProfileBundle", "(", "l", ".", "G", "(", ")", ".", "Log", ",", "logs", ".", "CPUProfile", ")", "\n", "}", "\n", "// Only add extended status if we're sending logs", "if", "mergeExtendedStatus", "{", "statusJSON", "=", "l", ".", "mergeExtendedStatus", "(", "statusJSON", ")", "\n", "}", "\n", "processesLog", "=", "keybaseProcessList", "(", ")", "\n", "}", "\n\n", "return", "l", ".", "post", "(", "mctx", ",", "statusJSON", ",", "feedback", ",", "kbfsLog", ",", "svcLog", ",", "ekLog", ",", "desktopLog", ",", "updaterLog", ",", "startLog", ",", "installLog", ",", "systemLog", ",", "gitLog", ",", "watchdogLog", ",", "traceBundle", ",", "cpuProfileBundle", ",", "uid", ",", "installID", ",", "processesLog", ")", "\n", "}" ]
// LogSend sends the tails of log files to kb, and also the last // few trace output files.
[ "LogSend", "sends", "the", "tails", "of", "log", "files", "to", "kb", "and", "also", "the", "last", "few", "trace", "output", "files", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/log_send.go#L491-L541
160,089
keybase/client
go/libkb/log_send.go
mergeExtendedStatus
func (l *LogSendContext) mergeExtendedStatus(status string) string { err := jsonw.EnsureMaxDepthBytesDefault([]byte(status)) if err != nil { return status } var statusObj map[string]interface{} if err = json.Unmarshal([]byte(status), &statusObj); err != nil { return status } extStatus, err := GetExtendedStatus(NewMetaContextTODO(l.G())) if err != nil { return status } statusMap := make(map[string]interface{}) statusMap["status"] = statusObj statusMap["extstatus"] = extStatus fullStatus, err := json.Marshal(statusMap) if err != nil { return status } return string(fullStatus) }
go
func (l *LogSendContext) mergeExtendedStatus(status string) string { err := jsonw.EnsureMaxDepthBytesDefault([]byte(status)) if err != nil { return status } var statusObj map[string]interface{} if err = json.Unmarshal([]byte(status), &statusObj); err != nil { return status } extStatus, err := GetExtendedStatus(NewMetaContextTODO(l.G())) if err != nil { return status } statusMap := make(map[string]interface{}) statusMap["status"] = statusObj statusMap["extstatus"] = extStatus fullStatus, err := json.Marshal(statusMap) if err != nil { return status } return string(fullStatus) }
[ "func", "(", "l", "*", "LogSendContext", ")", "mergeExtendedStatus", "(", "status", "string", ")", "string", "{", "err", ":=", "jsonw", ".", "EnsureMaxDepthBytesDefault", "(", "[", "]", "byte", "(", "status", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", "\n", "}", "\n\n", "var", "statusObj", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "status", ")", ",", "&", "statusObj", ")", ";", "err", "!=", "nil", "{", "return", "status", "\n", "}", "\n\n", "extStatus", ",", "err", ":=", "GetExtendedStatus", "(", "NewMetaContextTODO", "(", "l", ".", "G", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", "\n", "}", "\n\n", "statusMap", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "statusMap", "[", "\"", "\"", "]", "=", "statusObj", "\n", "statusMap", "[", "\"", "\"", "]", "=", "extStatus", "\n\n", "fullStatus", ",", "err", ":=", "json", ".", "Marshal", "(", "statusMap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "status", "\n", "}", "\n", "return", "string", "(", "fullStatus", ")", "\n", "}" ]
// mergeExtendedStatus adds the extended status to the given status json blob. // If any errors occur the original status is returned unmodified.
[ "mergeExtendedStatus", "adds", "the", "extended", "status", "to", "the", "given", "status", "json", "blob", ".", "If", "any", "errors", "occur", "the", "original", "status", "is", "returned", "unmodified", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/log_send.go#L545-L570
160,090
keybase/client
go/kbfs/libkbfs/protected_context.go
context
func (c *protectedContext) context() context.Context { c.mu.RLock() defer c.mu.RUnlock() return c.ctx }
go
func (c *protectedContext) context() context.Context { c.mu.RLock() defer c.mu.RUnlock() return c.ctx }
[ "func", "(", "c", "*", "protectedContext", ")", "context", "(", ")", "context", ".", "Context", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "ctx", "\n", "}" ]
// context returns the context stored in the protectedContext.
[ "context", "returns", "the", "context", "stored", "in", "the", "protectedContext", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/protected_context.go#L42-L46
160,091
keybase/client
go/chat/utils/utils.go
Collar
func Collar(lower int, ideal int, upper int) int { if ideal > upper { return upper } if ideal < lower { return lower } return ideal }
go
func Collar(lower int, ideal int, upper int) int { if ideal > upper { return upper } if ideal < lower { return lower } return ideal }
[ "func", "Collar", "(", "lower", "int", ",", "ideal", "int", ",", "upper", "int", ")", "int", "{", "if", "ideal", ">", "upper", "{", "return", "upper", "\n", "}", "\n", "if", "ideal", "<", "lower", "{", "return", "lower", "\n", "}", "\n", "return", "ideal", "\n", "}" ]
// upper bounds takes higher priority
[ "upper", "bounds", "takes", "higher", "priority" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L91-L99
160,092
keybase/client
go/chat/utils/utils.go
AggRateLimitsP
func AggRateLimitsP(rlimits []*chat1.RateLimit) (res []chat1.RateLimit) { m := make(map[string]chat1.RateLimit) for _, l := range rlimits { if l != nil { m[l.Name] = *l } } for _, v := range m { res = append(res, v) } return res }
go
func AggRateLimitsP(rlimits []*chat1.RateLimit) (res []chat1.RateLimit) { m := make(map[string]chat1.RateLimit) for _, l := range rlimits { if l != nil { m[l.Name] = *l } } for _, v := range m { res = append(res, v) } return res }
[ "func", "AggRateLimitsP", "(", "rlimits", "[", "]", "*", "chat1", ".", "RateLimit", ")", "(", "res", "[", "]", "chat1", ".", "RateLimit", ")", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "chat1", ".", "RateLimit", ")", "\n", "for", "_", ",", "l", ":=", "range", "rlimits", "{", "if", "l", "!=", "nil", "{", "m", "[", "l", ".", "Name", "]", "=", "*", "l", "\n", "}", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "m", "{", "res", "=", "append", "(", "res", ",", "v", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// AggRateLimitsP takes a list of rate limit responses and dedups them to the last one received // of each category
[ "AggRateLimitsP", "takes", "a", "list", "of", "rate", "limit", "responses", "and", "dedups", "them", "to", "the", "last", "one", "received", "of", "each", "category" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L103-L114
160,093
keybase/client
go/chat/utils/utils.go
ReorderParticipants
func ReorderParticipants(mctx libkb.MetaContext, g libkb.UIDMapperContext, umapper libkb.UIDMapper, tlfname string, activeList []gregor1.UID) (writerNames []chat1.ConversationLocalParticipant, err error) { srcWriterNames, _, _, err := splitAndNormalizeTLFNameCanonicalize(mctx.G(), tlfname, false) if err != nil { return writerNames, err } var activeKuids []keybase1.UID for _, a := range activeList { activeKuids = append(activeKuids, keybase1.UID(a.String())) } packages, err := umapper.MapUIDsToUsernamePackages(mctx.Ctx(), g, activeKuids, time.Hour*24, 10*time.Second, true) activeMap := make(map[string]chat1.ConversationLocalParticipant) if err == nil { for i := 0; i < len(activeKuids); i++ { activeMap[activeKuids[i].String()] = UsernamePackageToParticipant(packages[i]) } } allowedWriters := make(map[string]bool) // Allow all writers from tlfname. for _, user := range srcWriterNames { allowedWriters[user] = true } // Fill from the active list first. for _, uid := range activeList { kbUID := keybase1.UID(uid.String()) p, ok := activeMap[kbUID.String()] if !ok { continue } if allowed, _ := allowedWriters[p.Username]; allowed { writerNames = append(writerNames, p) // Allow only one occurrence. allowedWriters[p.Username] = false } } // Include participants even if they weren't in the active list, in stable order. for _, user := range srcWriterNames { if allowed, _ := allowedWriters[user]; allowed { writerNames = append(writerNames, UsernamePackageToParticipant(libkb.UsernamePackage{ NormalizedUsername: libkb.NewNormalizedUsername(user), FullName: nil, })) allowedWriters[user] = false } } return writerNames, nil }
go
func ReorderParticipants(mctx libkb.MetaContext, g libkb.UIDMapperContext, umapper libkb.UIDMapper, tlfname string, activeList []gregor1.UID) (writerNames []chat1.ConversationLocalParticipant, err error) { srcWriterNames, _, _, err := splitAndNormalizeTLFNameCanonicalize(mctx.G(), tlfname, false) if err != nil { return writerNames, err } var activeKuids []keybase1.UID for _, a := range activeList { activeKuids = append(activeKuids, keybase1.UID(a.String())) } packages, err := umapper.MapUIDsToUsernamePackages(mctx.Ctx(), g, activeKuids, time.Hour*24, 10*time.Second, true) activeMap := make(map[string]chat1.ConversationLocalParticipant) if err == nil { for i := 0; i < len(activeKuids); i++ { activeMap[activeKuids[i].String()] = UsernamePackageToParticipant(packages[i]) } } allowedWriters := make(map[string]bool) // Allow all writers from tlfname. for _, user := range srcWriterNames { allowedWriters[user] = true } // Fill from the active list first. for _, uid := range activeList { kbUID := keybase1.UID(uid.String()) p, ok := activeMap[kbUID.String()] if !ok { continue } if allowed, _ := allowedWriters[p.Username]; allowed { writerNames = append(writerNames, p) // Allow only one occurrence. allowedWriters[p.Username] = false } } // Include participants even if they weren't in the active list, in stable order. for _, user := range srcWriterNames { if allowed, _ := allowedWriters[user]; allowed { writerNames = append(writerNames, UsernamePackageToParticipant(libkb.UsernamePackage{ NormalizedUsername: libkb.NewNormalizedUsername(user), FullName: nil, })) allowedWriters[user] = false } } return writerNames, nil }
[ "func", "ReorderParticipants", "(", "mctx", "libkb", ".", "MetaContext", ",", "g", "libkb", ".", "UIDMapperContext", ",", "umapper", "libkb", ".", "UIDMapper", ",", "tlfname", "string", ",", "activeList", "[", "]", "gregor1", ".", "UID", ")", "(", "writerNames", "[", "]", "chat1", ".", "ConversationLocalParticipant", ",", "err", "error", ")", "{", "srcWriterNames", ",", "_", ",", "_", ",", "err", ":=", "splitAndNormalizeTLFNameCanonicalize", "(", "mctx", ".", "G", "(", ")", ",", "tlfname", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "writerNames", ",", "err", "\n", "}", "\n", "var", "activeKuids", "[", "]", "keybase1", ".", "UID", "\n", "for", "_", ",", "a", ":=", "range", "activeList", "{", "activeKuids", "=", "append", "(", "activeKuids", ",", "keybase1", ".", "UID", "(", "a", ".", "String", "(", ")", ")", ")", "\n", "}", "\n", "packages", ",", "err", ":=", "umapper", ".", "MapUIDsToUsernamePackages", "(", "mctx", ".", "Ctx", "(", ")", ",", "g", ",", "activeKuids", ",", "time", ".", "Hour", "*", "24", ",", "10", "*", "time", ".", "Second", ",", "true", ")", "\n", "activeMap", ":=", "make", "(", "map", "[", "string", "]", "chat1", ".", "ConversationLocalParticipant", ")", "\n", "if", "err", "==", "nil", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "activeKuids", ")", ";", "i", "++", "{", "activeMap", "[", "activeKuids", "[", "i", "]", ".", "String", "(", ")", "]", "=", "UsernamePackageToParticipant", "(", "packages", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "allowedWriters", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n\n", "// Allow all writers from tlfname.", "for", "_", ",", "user", ":=", "range", "srcWriterNames", "{", "allowedWriters", "[", "user", "]", "=", "true", "\n", "}", "\n\n", "// Fill from the active list first.", "for", "_", ",", "uid", ":=", "range", "activeList", "{", "kbUID", ":=", "keybase1", ".", "UID", "(", "uid", ".", "String", "(", ")", ")", "\n", "p", ",", "ok", ":=", "activeMap", "[", "kbUID", ".", "String", "(", ")", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "if", "allowed", ",", "_", ":=", "allowedWriters", "[", "p", ".", "Username", "]", ";", "allowed", "{", "writerNames", "=", "append", "(", "writerNames", ",", "p", ")", "\n", "// Allow only one occurrence.", "allowedWriters", "[", "p", ".", "Username", "]", "=", "false", "\n", "}", "\n", "}", "\n\n", "// Include participants even if they weren't in the active list, in stable order.", "for", "_", ",", "user", ":=", "range", "srcWriterNames", "{", "if", "allowed", ",", "_", ":=", "allowedWriters", "[", "user", "]", ";", "allowed", "{", "writerNames", "=", "append", "(", "writerNames", ",", "UsernamePackageToParticipant", "(", "libkb", ".", "UsernamePackage", "{", "NormalizedUsername", ":", "libkb", ".", "NewNormalizedUsername", "(", "user", ")", ",", "FullName", ":", "nil", ",", "}", ")", ")", "\n", "allowedWriters", "[", "user", "]", "=", "false", "\n", "}", "\n", "}", "\n\n", "return", "writerNames", ",", "nil", "\n", "}" ]
// ReorderParticipants based on the order in activeList. // Only allows usernames from tlfname in the output. // This never fails, worse comes to worst it just returns the split of tlfname.
[ "ReorderParticipants", "based", "on", "the", "order", "in", "activeList", ".", "Only", "allows", "usernames", "from", "tlfname", "in", "the", "output", ".", "This", "never", "fails", "worse", "comes", "to", "worst", "it", "just", "returns", "the", "split", "of", "tlfname", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L130-L181
160,094
keybase/client
go/chat/utils/utils.go
splitAndNormalizeTLFNameCanonicalize
func splitAndNormalizeTLFNameCanonicalize(g *libkb.GlobalContext, name string, public bool) (writerNames, readerNames []string, extensionSuffix string, err error) { writerNames, readerNames, extensionSuffix, err = SplitAndNormalizeTLFName(g, name, public) if retryErr, retry := err.(TlfNameNotCanonical); retry { return SplitAndNormalizeTLFName(g, retryErr.NameToTry, public) } return writerNames, readerNames, extensionSuffix, err }
go
func splitAndNormalizeTLFNameCanonicalize(g *libkb.GlobalContext, name string, public bool) (writerNames, readerNames []string, extensionSuffix string, err error) { writerNames, readerNames, extensionSuffix, err = SplitAndNormalizeTLFName(g, name, public) if retryErr, retry := err.(TlfNameNotCanonical); retry { return SplitAndNormalizeTLFName(g, retryErr.NameToTry, public) } return writerNames, readerNames, extensionSuffix, err }
[ "func", "splitAndNormalizeTLFNameCanonicalize", "(", "g", "*", "libkb", ".", "GlobalContext", ",", "name", "string", ",", "public", "bool", ")", "(", "writerNames", ",", "readerNames", "[", "]", "string", ",", "extensionSuffix", "string", ",", "err", "error", ")", "{", "writerNames", ",", "readerNames", ",", "extensionSuffix", ",", "err", "=", "SplitAndNormalizeTLFName", "(", "g", ",", "name", ",", "public", ")", "\n", "if", "retryErr", ",", "retry", ":=", "err", ".", "(", "TlfNameNotCanonical", ")", ";", "retry", "{", "return", "SplitAndNormalizeTLFName", "(", "g", ",", "retryErr", ".", "NameToTry", ",", "public", ")", "\n", "}", "\n", "return", "writerNames", ",", "readerNames", ",", "extensionSuffix", ",", "err", "\n", "}" ]
// Drive splitAndNormalizeTLFName with one attempt to follow TlfNameNotCanonical.
[ "Drive", "splitAndNormalizeTLFName", "with", "one", "attempt", "to", "follow", "TlfNameNotCanonical", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L184-L190
160,095
keybase/client
go/chat/utils/utils.go
GetConversationStatusBehavior
func GetConversationStatusBehavior(s chat1.ConversationStatus) ConversationStatusBehavior { switch s { case chat1.ConversationStatus_UNFILED: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_FAVORITE: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_IGNORED: return ConversationStatusBehavior{ ShowInInbox: false, SendingRemovesStatus: true, ActivityRemovesStatus: true, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_REPORTED: fallthrough case chat1.ConversationStatus_BLOCKED: return ConversationStatusBehavior{ ShowInInbox: false, SendingRemovesStatus: true, ActivityRemovesStatus: false, DesktopNotifications: false, PushNotifications: false, ShowBadges: false, } case chat1.ConversationStatus_MUTED: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: false, PushNotifications: false, ShowBadges: false, } default: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } } }
go
func GetConversationStatusBehavior(s chat1.ConversationStatus) ConversationStatusBehavior { switch s { case chat1.ConversationStatus_UNFILED: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_FAVORITE: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_IGNORED: return ConversationStatusBehavior{ ShowInInbox: false, SendingRemovesStatus: true, ActivityRemovesStatus: true, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } case chat1.ConversationStatus_REPORTED: fallthrough case chat1.ConversationStatus_BLOCKED: return ConversationStatusBehavior{ ShowInInbox: false, SendingRemovesStatus: true, ActivityRemovesStatus: false, DesktopNotifications: false, PushNotifications: false, ShowBadges: false, } case chat1.ConversationStatus_MUTED: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: false, PushNotifications: false, ShowBadges: false, } default: return ConversationStatusBehavior{ ShowInInbox: true, SendingRemovesStatus: false, ActivityRemovesStatus: false, DesktopNotifications: true, PushNotifications: true, ShowBadges: true, } } }
[ "func", "GetConversationStatusBehavior", "(", "s", "chat1", ".", "ConversationStatus", ")", "ConversationStatusBehavior", "{", "switch", "s", "{", "case", "chat1", ".", "ConversationStatus_UNFILED", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "true", ",", "SendingRemovesStatus", ":", "false", ",", "ActivityRemovesStatus", ":", "false", ",", "DesktopNotifications", ":", "true", ",", "PushNotifications", ":", "true", ",", "ShowBadges", ":", "true", ",", "}", "\n", "case", "chat1", ".", "ConversationStatus_FAVORITE", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "true", ",", "SendingRemovesStatus", ":", "false", ",", "ActivityRemovesStatus", ":", "false", ",", "DesktopNotifications", ":", "true", ",", "PushNotifications", ":", "true", ",", "ShowBadges", ":", "true", ",", "}", "\n", "case", "chat1", ".", "ConversationStatus_IGNORED", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "false", ",", "SendingRemovesStatus", ":", "true", ",", "ActivityRemovesStatus", ":", "true", ",", "DesktopNotifications", ":", "true", ",", "PushNotifications", ":", "true", ",", "ShowBadges", ":", "true", ",", "}", "\n", "case", "chat1", ".", "ConversationStatus_REPORTED", ":", "fallthrough", "\n", "case", "chat1", ".", "ConversationStatus_BLOCKED", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "false", ",", "SendingRemovesStatus", ":", "true", ",", "ActivityRemovesStatus", ":", "false", ",", "DesktopNotifications", ":", "false", ",", "PushNotifications", ":", "false", ",", "ShowBadges", ":", "false", ",", "}", "\n", "case", "chat1", ".", "ConversationStatus_MUTED", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "true", ",", "SendingRemovesStatus", ":", "false", ",", "ActivityRemovesStatus", ":", "false", ",", "DesktopNotifications", ":", "false", ",", "PushNotifications", ":", "false", ",", "ShowBadges", ":", "false", ",", "}", "\n", "default", ":", "return", "ConversationStatusBehavior", "{", "ShowInInbox", ":", "true", ",", "SendingRemovesStatus", ":", "false", ",", "ActivityRemovesStatus", ":", "false", ",", "DesktopNotifications", ":", "true", ",", "PushNotifications", ":", "true", ",", "ShowBadges", ":", "true", ",", "}", "\n", "}", "\n", "}" ]
// GetConversationStatusBehavior gives information about what is allowed for a conversation status. // When changing these, be sure to update gregor's postMessage as well
[ "GetConversationStatusBehavior", "gives", "information", "about", "what", "is", "allowed", "for", "a", "conversation", "status", ".", "When", "changing", "these", "be", "sure", "to", "update", "gregor", "s", "postMessage", "as", "well" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L290-L349
160,096
keybase/client
go/chat/utils/utils.go
VisibleChatConversationStatuses
func VisibleChatConversationStatuses() (res []chat1.ConversationStatus) { for _, s := range chat1.ConversationStatusMap { if GetConversationStatusBehavior(s).ShowInInbox { res = append(res, s) } } sort.Sort(byConversationStatus(res)) return }
go
func VisibleChatConversationStatuses() (res []chat1.ConversationStatus) { for _, s := range chat1.ConversationStatusMap { if GetConversationStatusBehavior(s).ShowInInbox { res = append(res, s) } } sort.Sort(byConversationStatus(res)) return }
[ "func", "VisibleChatConversationStatuses", "(", ")", "(", "res", "[", "]", "chat1", ".", "ConversationStatus", ")", "{", "for", "_", ",", "s", ":=", "range", "chat1", ".", "ConversationStatusMap", "{", "if", "GetConversationStatusBehavior", "(", "s", ")", ".", "ShowInInbox", "{", "res", "=", "append", "(", "res", ",", "s", ")", "\n", "}", "\n", "}", "\n", "sort", ".", "Sort", "(", "byConversationStatus", "(", "res", ")", ")", "\n", "return", "\n", "}" ]
// Which convs show in the inbox.
[ "Which", "convs", "show", "in", "the", "inbox", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L358-L366
160,097
keybase/client
go/chat/utils/utils.go
FilterByType
func FilterByType(msgs []chat1.MessageUnboxed, query *chat1.GetThreadQuery, includeAllErrors bool) (res []chat1.MessageUnboxed) { useTypeFilter := (query != nil && len(query.MessageTypes) > 0) typmap := make(map[chat1.MessageType]bool) if useTypeFilter { for _, mt := range query.MessageTypes { typmap[mt] = true } } for _, msg := range msgs { state, err := msg.State() if err != nil { if includeAllErrors { res = append(res, msg) } continue } switch state { case chat1.MessageUnboxedState_ERROR: if includeAllErrors { res = append(res, msg) } case chat1.MessageUnboxedState_PLACEHOLDER: // We don't know what the type is for these, so just include them res = append(res, msg) default: _, match := typmap[msg.GetMessageType()] if !useTypeFilter || match { res = append(res, msg) } } } return res }
go
func FilterByType(msgs []chat1.MessageUnboxed, query *chat1.GetThreadQuery, includeAllErrors bool) (res []chat1.MessageUnboxed) { useTypeFilter := (query != nil && len(query.MessageTypes) > 0) typmap := make(map[chat1.MessageType]bool) if useTypeFilter { for _, mt := range query.MessageTypes { typmap[mt] = true } } for _, msg := range msgs { state, err := msg.State() if err != nil { if includeAllErrors { res = append(res, msg) } continue } switch state { case chat1.MessageUnboxedState_ERROR: if includeAllErrors { res = append(res, msg) } case chat1.MessageUnboxedState_PLACEHOLDER: // We don't know what the type is for these, so just include them res = append(res, msg) default: _, match := typmap[msg.GetMessageType()] if !useTypeFilter || match { res = append(res, msg) } } } return res }
[ "func", "FilterByType", "(", "msgs", "[", "]", "chat1", ".", "MessageUnboxed", ",", "query", "*", "chat1", ".", "GetThreadQuery", ",", "includeAllErrors", "bool", ")", "(", "res", "[", "]", "chat1", ".", "MessageUnboxed", ")", "{", "useTypeFilter", ":=", "(", "query", "!=", "nil", "&&", "len", "(", "query", ".", "MessageTypes", ")", ">", "0", ")", "\n\n", "typmap", ":=", "make", "(", "map", "[", "chat1", ".", "MessageType", "]", "bool", ")", "\n", "if", "useTypeFilter", "{", "for", "_", ",", "mt", ":=", "range", "query", ".", "MessageTypes", "{", "typmap", "[", "mt", "]", "=", "true", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "msg", ":=", "range", "msgs", "{", "state", ",", "err", ":=", "msg", ".", "State", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "includeAllErrors", "{", "res", "=", "append", "(", "res", ",", "msg", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "switch", "state", "{", "case", "chat1", ".", "MessageUnboxedState_ERROR", ":", "if", "includeAllErrors", "{", "res", "=", "append", "(", "res", ",", "msg", ")", "\n", "}", "\n", "case", "chat1", ".", "MessageUnboxedState_PLACEHOLDER", ":", "// We don't know what the type is for these, so just include them", "res", "=", "append", "(", "res", ",", "msg", ")", "\n", "default", ":", "_", ",", "match", ":=", "typmap", "[", "msg", ".", "GetMessageType", "(", ")", "]", "\n", "if", "!", "useTypeFilter", "||", "match", "{", "res", "=", "append", "(", "res", ",", "msg", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "res", "\n", "}" ]
// FilterByType filters messages based on a query. // If includeAllErrors then MessageUnboxedError are all returned. Otherwise, they are filtered based on type. // Messages whose type cannot be determined are considered errors.
[ "FilterByType", "filters", "messages", "based", "on", "a", "query", ".", "If", "includeAllErrors", "then", "MessageUnboxedError", "are", "all", "returned", ".", "Otherwise", "they", "are", "filtered", "based", "on", "type", ".", "Messages", "whose", "type", "cannot", "be", "determined", "are", "considered", "errors", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L467-L501
160,098
keybase/client
go/chat/utils/utils.go
GetSupersedes
func GetSupersedes(msg chat1.MessageUnboxed) ([]chat1.MessageID, error) { if !msg.IsValidFull() { return nil, fmt.Errorf("GetSupersedes called with invalid message: %v", msg.GetMessageID()) } body := msg.Valid().MessageBody typ, err := body.MessageType() if err != nil { return nil, err } // We use the message ID in the body over the field in the client header to // avoid server trust. switch typ { case chat1.MessageType_EDIT: return []chat1.MessageID{msg.Valid().MessageBody.Edit().MessageID}, nil case chat1.MessageType_REACTION: return []chat1.MessageID{msg.Valid().MessageBody.Reaction().MessageID}, nil case chat1.MessageType_DELETE: return msg.Valid().MessageBody.Delete().MessageIDs, nil case chat1.MessageType_ATTACHMENTUPLOADED: return []chat1.MessageID{msg.Valid().MessageBody.Attachmentuploaded().MessageID}, nil case chat1.MessageType_UNFURL: return []chat1.MessageID{msg.Valid().MessageBody.Unfurl().MessageID}, nil default: return nil, nil } }
go
func GetSupersedes(msg chat1.MessageUnboxed) ([]chat1.MessageID, error) { if !msg.IsValidFull() { return nil, fmt.Errorf("GetSupersedes called with invalid message: %v", msg.GetMessageID()) } body := msg.Valid().MessageBody typ, err := body.MessageType() if err != nil { return nil, err } // We use the message ID in the body over the field in the client header to // avoid server trust. switch typ { case chat1.MessageType_EDIT: return []chat1.MessageID{msg.Valid().MessageBody.Edit().MessageID}, nil case chat1.MessageType_REACTION: return []chat1.MessageID{msg.Valid().MessageBody.Reaction().MessageID}, nil case chat1.MessageType_DELETE: return msg.Valid().MessageBody.Delete().MessageIDs, nil case chat1.MessageType_ATTACHMENTUPLOADED: return []chat1.MessageID{msg.Valid().MessageBody.Attachmentuploaded().MessageID}, nil case chat1.MessageType_UNFURL: return []chat1.MessageID{msg.Valid().MessageBody.Unfurl().MessageID}, nil default: return nil, nil } }
[ "func", "GetSupersedes", "(", "msg", "chat1", ".", "MessageUnboxed", ")", "(", "[", "]", "chat1", ".", "MessageID", ",", "error", ")", "{", "if", "!", "msg", ".", "IsValidFull", "(", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "msg", ".", "GetMessageID", "(", ")", ")", "\n", "}", "\n", "body", ":=", "msg", ".", "Valid", "(", ")", ".", "MessageBody", "\n", "typ", ",", "err", ":=", "body", ".", "MessageType", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// We use the message ID in the body over the field in the client header to", "// avoid server trust.", "switch", "typ", "{", "case", "chat1", ".", "MessageType_EDIT", ":", "return", "[", "]", "chat1", ".", "MessageID", "{", "msg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Edit", "(", ")", ".", "MessageID", "}", ",", "nil", "\n", "case", "chat1", ".", "MessageType_REACTION", ":", "return", "[", "]", "chat1", ".", "MessageID", "{", "msg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Reaction", "(", ")", ".", "MessageID", "}", ",", "nil", "\n", "case", "chat1", ".", "MessageType_DELETE", ":", "return", "msg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Delete", "(", ")", ".", "MessageIDs", ",", "nil", "\n", "case", "chat1", ".", "MessageType_ATTACHMENTUPLOADED", ":", "return", "[", "]", "chat1", ".", "MessageID", "{", "msg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Attachmentuploaded", "(", ")", ".", "MessageID", "}", ",", "nil", "\n", "case", "chat1", ".", "MessageType_UNFURL", ":", "return", "[", "]", "chat1", ".", "MessageID", "{", "msg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Unfurl", "(", ")", ".", "MessageID", "}", ",", "nil", "\n", "default", ":", "return", "nil", ",", "nil", "\n", "}", "\n", "}" ]
// GetSupersedes must be called with a valid msg
[ "GetSupersedes", "must", "be", "called", "with", "a", "valid", "msg" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L541-L567
160,099
keybase/client
go/chat/utils/utils.go
getSenderPrefix
func getSenderPrefix(mvalid chat1.MessageUnboxedValid, conv chat1.ConversationLocal, currentUsername string) (senderPrefix string) { if showSenderPrefix(mvalid, conv) { sender := mvalid.SenderUsername if sender == currentUsername { senderPrefix = "You: " } else { senderPrefix = fmt.Sprintf("%s: ", sender) } } return senderPrefix }
go
func getSenderPrefix(mvalid chat1.MessageUnboxedValid, conv chat1.ConversationLocal, currentUsername string) (senderPrefix string) { if showSenderPrefix(mvalid, conv) { sender := mvalid.SenderUsername if sender == currentUsername { senderPrefix = "You: " } else { senderPrefix = fmt.Sprintf("%s: ", sender) } } return senderPrefix }
[ "func", "getSenderPrefix", "(", "mvalid", "chat1", ".", "MessageUnboxedValid", ",", "conv", "chat1", ".", "ConversationLocal", ",", "currentUsername", "string", ")", "(", "senderPrefix", "string", ")", "{", "if", "showSenderPrefix", "(", "mvalid", ",", "conv", ")", "{", "sender", ":=", "mvalid", ".", "SenderUsername", "\n", "if", "sender", "==", "currentUsername", "{", "senderPrefix", "=", "\"", "\"", "\n", "}", "else", "{", "senderPrefix", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "sender", ")", "\n", "}", "\n", "}", "\n", "return", "senderPrefix", "\n", "}" ]
// Sender prefix for msg snippets. Will show if a conversation has > 2 members // or is of type TEAM
[ "Sender", "prefix", "for", "msg", "snippets", ".", "Will", "show", "if", "a", "conversation", "has", ">", "2", "members", "or", "is", "of", "type", "TEAM" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/utils/utils.go#L895-L905