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
161,300
keybase/client
go/kbfs/libpages/config/config_v1.go
Encode
func (c *V1) Encode(w io.Writer, prettify bool) error { encoder := json.NewEncoder(w) if prettify { encoder.SetIndent("", strings.Repeat(" ", 2)) } return encoder.Encode(c) }
go
func (c *V1) Encode(w io.Writer, prettify bool) error { encoder := json.NewEncoder(w) if prettify { encoder.SetIndent("", strings.Repeat(" ", 2)) } return encoder.Encode(c) }
[ "func", "(", "c", "*", "V1", ")", "Encode", "(", "w", "io", ".", "Writer", ",", "prettify", "bool", ")", "error", "{", "encoder", ":=", "json", ".", "NewEncoder", "(", "w", ")", "\n", "if", "prettify", "{", "encoder", ".", "SetIndent", "(", "\"", "\"", ",", "strings", ".", "Repeat", "(", "\"", "\"", ",", "2", ")", ")", "\n", "}", "\n", "return", "encoder", ".", "Encode", "(", "c", ")", "\n", "}" ]
// Encode implements the Config interface.
[ "Encode", "implements", "the", "Config", "interface", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L122-L128
161,301
keybase/client
go/kbfs/libpages/config/config_v1.go
HasBcryptPasswords
func (c *V1) HasBcryptPasswords() (bool, error) { if err := c.EnsureInit(); err != nil { return false, err } for _, pass := range c.users { if pass.passwordType() == passwordTypeBcrypt { return true, nil } } return false, nil }
go
func (c *V1) HasBcryptPasswords() (bool, error) { if err := c.EnsureInit(); err != nil { return false, err } for _, pass := range c.users { if pass.passwordType() == passwordTypeBcrypt { return true, nil } } return false, nil }
[ "func", "(", "c", "*", "V1", ")", "HasBcryptPasswords", "(", ")", "(", "bool", ",", "error", ")", "{", "if", "err", ":=", "c", ".", "EnsureInit", "(", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "for", "_", ",", "pass", ":=", "range", "c", ".", "users", "{", "if", "pass", ".", "passwordType", "(", ")", "==", "passwordTypeBcrypt", "{", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// HasBcryptPasswords checks if any password hash in the config is a bcrypt // hash. This method is temporary for migration and will go away.
[ "HasBcryptPasswords", "checks", "if", "any", "password", "hash", "in", "the", "config", "is", "a", "bcrypt", "hash", ".", "This", "method", "is", "temporary", "for", "migration", "and", "will", "go", "away", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libpages/config/config_v1.go#L147-L157
161,302
keybase/client
go/teams/box_audit.go
BoxAuditTeam
func (a *BoxAuditor) BoxAuditTeam(mctx libkb.MetaContext, teamID keybase1.TeamID) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed(fmt.Sprintf("BoxAuditTeam(%s)", teamID), func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not auditing...") return nil, nil } lock := a.locktab.AcquireOnName(mctx.Ctx(), mctx.G(), teamID.String()) defer lock.Release(mctx.Ctx()) return a.boxAuditTeamLocked(mctx, teamID) }
go
func (a *BoxAuditor) BoxAuditTeam(mctx libkb.MetaContext, teamID keybase1.TeamID) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed(fmt.Sprintf("BoxAuditTeam(%s)", teamID), func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not auditing...") return nil, nil } lock := a.locktab.AcquireOnName(mctx.Ctx(), mctx.G(), teamID.String()) defer lock.Release(mctx.Ctx()) return a.boxAuditTeamLocked(mctx, teamID) }
[ "func", "(", "a", "*", "BoxAuditor", ")", "BoxAuditTeam", "(", "mctx", "libkb", ".", "MetaContext", ",", "teamID", "keybase1", ".", "TeamID", ")", "(", "attempt", "*", "keybase1", ".", "BoxAuditAttempt", ",", "err", "error", ")", "{", "mctx", "=", "a", ".", "initMctx", "(", "mctx", ")", "\n", "defer", "mctx", ".", "TraceTimed", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "teamID", ")", ",", "func", "(", ")", "error", "{", "return", "err", "}", ")", "(", ")", "\n\n", "if", "!", "ShouldRunBoxAudit", "(", "mctx", ")", "{", "mctx", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "lock", ":=", "a", ".", "locktab", ".", "AcquireOnName", "(", "mctx", ".", "Ctx", "(", ")", ",", "mctx", ".", "G", "(", ")", ",", "teamID", ".", "String", "(", ")", ")", "\n", "defer", "lock", ".", "Release", "(", "mctx", ".", "Ctx", "(", ")", ")", "\n", "return", "a", ".", "boxAuditTeamLocked", "(", "mctx", ",", "teamID", ")", "\n", "}" ]
// BoxAuditTeam performs one attempt of a BoxAudit. If one is in progress for // the teamid, make a new attempt. If exceeded max tries or hit a malicious // error, return a fatal error. Otherwise, make a new audit and fill it with // one attempt. If the attempt failed nonfatally, enqueue it in the retry // queue. If it failed fatally, add it to the jail. If it failed for reasons // that are purely client-side, like a disk write error, we retry it as well // but distinguish it from a failure the server could have possibly maliciously // caused.
[ "BoxAuditTeam", "performs", "one", "attempt", "of", "a", "BoxAudit", ".", "If", "one", "is", "in", "progress", "for", "the", "teamid", "make", "a", "new", "attempt", ".", "If", "exceeded", "max", "tries", "or", "hit", "a", "malicious", "error", "return", "a", "fatal", "error", ".", "Otherwise", "make", "a", "new", "audit", "and", "fill", "it", "with", "one", "attempt", ".", "If", "the", "attempt", "failed", "nonfatally", "enqueue", "it", "in", "the", "retry", "queue", ".", "If", "it", "failed", "fatally", "add", "it", "to", "the", "jail", ".", "If", "it", "failed", "for", "reasons", "that", "are", "purely", "client", "-", "side", "like", "a", "disk", "write", "error", "we", "retry", "it", "as", "well", "but", "distinguish", "it", "from", "a", "failure", "the", "server", "could", "have", "possibly", "maliciously", "caused", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/box_audit.go#L169-L181
161,303
keybase/client
go/teams/box_audit.go
RetryNextBoxAudit
func (a *BoxAuditor) RetryNextBoxAudit(mctx libkb.MetaContext) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed("RetryNextBoxAudit", func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not RetryNextBoxAuditing...") return nil, nil } queueItem, err := a.popRetryQueue(mctx) if err != nil { return nil, err } if queueItem == nil { mctx.Debug("Retry queue empty, succeeding vacuously") return nil, nil } return a.BoxAuditTeam(mctx, (*queueItem).TeamID) }
go
func (a *BoxAuditor) RetryNextBoxAudit(mctx libkb.MetaContext) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed("RetryNextBoxAudit", func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not RetryNextBoxAuditing...") return nil, nil } queueItem, err := a.popRetryQueue(mctx) if err != nil { return nil, err } if queueItem == nil { mctx.Debug("Retry queue empty, succeeding vacuously") return nil, nil } return a.BoxAuditTeam(mctx, (*queueItem).TeamID) }
[ "func", "(", "a", "*", "BoxAuditor", ")", "RetryNextBoxAudit", "(", "mctx", "libkb", ".", "MetaContext", ")", "(", "attempt", "*", "keybase1", ".", "BoxAuditAttempt", ",", "err", "error", ")", "{", "mctx", "=", "a", ".", "initMctx", "(", "mctx", ")", "\n", "defer", "mctx", ".", "TraceTimed", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "return", "err", "}", ")", "(", ")", "\n\n", "if", "!", "ShouldRunBoxAudit", "(", "mctx", ")", "{", "mctx", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "queueItem", ",", "err", ":=", "a", ".", "popRetryQueue", "(", "mctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "queueItem", "==", "nil", "{", "mctx", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "a", ".", "BoxAuditTeam", "(", "mctx", ",", "(", "*", "queueItem", ")", ".", "TeamID", ")", "\n", "}" ]
// RetryNextBoxAudit selects a teamID from the box audit retry queue and performs another box audit.
[ "RetryNextBoxAudit", "selects", "a", "teamID", "from", "the", "box", "audit", "retry", "queue", "and", "performs", "another", "box", "audit", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/box_audit.go#L302-L320
161,304
keybase/client
go/teams/box_audit.go
BoxAuditRandomTeam
func (a *BoxAuditor) BoxAuditRandomTeam(mctx libkb.MetaContext) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed("BoxAuditRandomTeam", func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not BoxAuditRandomTeaming...") return nil, nil } teamID, err := randomKnownTeamID(mctx) if err != nil { return nil, err } if teamID == nil { mctx.Debug("No known teams to audit in db, skipping box audit") return nil, nil } return a.BoxAuditTeam(mctx, *teamID) }
go
func (a *BoxAuditor) BoxAuditRandomTeam(mctx libkb.MetaContext) (attempt *keybase1.BoxAuditAttempt, err error) { mctx = a.initMctx(mctx) defer mctx.TraceTimed("BoxAuditRandomTeam", func() error { return err })() if !ShouldRunBoxAudit(mctx) { mctx.Debug("Box auditor feature flagged off; not BoxAuditRandomTeaming...") return nil, nil } teamID, err := randomKnownTeamID(mctx) if err != nil { return nil, err } if teamID == nil { mctx.Debug("No known teams to audit in db, skipping box audit") return nil, nil } return a.BoxAuditTeam(mctx, *teamID) }
[ "func", "(", "a", "*", "BoxAuditor", ")", "BoxAuditRandomTeam", "(", "mctx", "libkb", ".", "MetaContext", ")", "(", "attempt", "*", "keybase1", ".", "BoxAuditAttempt", ",", "err", "error", ")", "{", "mctx", "=", "a", ".", "initMctx", "(", "mctx", ")", "\n", "defer", "mctx", ".", "TraceTimed", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "return", "err", "}", ")", "(", ")", "\n\n", "if", "!", "ShouldRunBoxAudit", "(", "mctx", ")", "{", "mctx", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "teamID", ",", "err", ":=", "randomKnownTeamID", "(", "mctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "teamID", "==", "nil", "{", "mctx", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "nil", "\n", "}", "\n\n", "return", "a", ".", "BoxAuditTeam", "(", "mctx", ",", "*", "teamID", ")", "\n", "}" ]
// BoxAuditRandomTeam selects a random known team from the slow team or FTL // cache, including implicit teams, and audits it. It may succeed trivially // because, for example, user is a reader and so does not have permissions to // do a box audit or the team is an open team.
[ "BoxAuditRandomTeam", "selects", "a", "random", "known", "team", "from", "the", "slow", "team", "or", "FTL", "cache", "including", "implicit", "teams", "and", "audits", "it", ".", "It", "may", "succeed", "trivially", "because", "for", "example", "user", "is", "a", "reader", "and", "so", "does", "not", "have", "permissions", "to", "do", "a", "box", "audit", "or", "the", "team", "is", "an", "open", "team", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/box_audit.go#L326-L345
161,305
keybase/client
go/teams/box_audit.go
calculateChainSummary
func calculateChainSummary(mctx libkb.MetaContext, team *Team) (summary *boxPublicSummary, err error) { defer mctx.TraceTimed(fmt.Sprintf("calculateChainSummary(%s)", team.ID), func() error { return err })() merkleSeqno, err := merkleSeqnoAtGenerationInception(mctx, team.chain()) if err != nil { return nil, err } return calculateSummaryAtMerkleSeqno(mctx, team, merkleSeqno, true) }
go
func calculateChainSummary(mctx libkb.MetaContext, team *Team) (summary *boxPublicSummary, err error) { defer mctx.TraceTimed(fmt.Sprintf("calculateChainSummary(%s)", team.ID), func() error { return err })() merkleSeqno, err := merkleSeqnoAtGenerationInception(mctx, team.chain()) if err != nil { return nil, err } return calculateSummaryAtMerkleSeqno(mctx, team, merkleSeqno, true) }
[ "func", "calculateChainSummary", "(", "mctx", "libkb", ".", "MetaContext", ",", "team", "*", "Team", ")", "(", "summary", "*", "boxPublicSummary", ",", "err", "error", ")", "{", "defer", "mctx", ".", "TraceTimed", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "team", ".", "ID", ")", ",", "func", "(", ")", "error", "{", "return", "err", "}", ")", "(", ")", "\n\n", "merkleSeqno", ",", "err", ":=", "merkleSeqnoAtGenerationInception", "(", "mctx", ",", "team", ".", "chain", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "calculateSummaryAtMerkleSeqno", "(", "mctx", ",", "team", ",", "merkleSeqno", ",", "true", ")", "\n", "}" ]
// calculateChainSummary calculates the box summary as implied by the team sigchain and previous links, // using the last known rotation and subsequent additions as markers for PUK freshness.
[ "calculateChainSummary", "calculates", "the", "box", "summary", "as", "implied", "by", "the", "team", "sigchain", "and", "previous", "links", "using", "the", "last", "known", "rotation", "and", "subsequent", "additions", "as", "markers", "for", "PUK", "freshness", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/box_audit.go#L842-L850
161,306
keybase/client
go/teams/box_audit.go
merkleSeqnoAtGenerationInception
func merkleSeqnoAtGenerationInception(mctx libkb.MetaContext, teamchain *TeamSigChainState) (merkleSeqno keybase1.Seqno, err error) { ptk, err := teamchain.GetLatestPerTeamKey() if err != nil { return 0, err } sigchainSeqno := ptk.Seqno root := teamchain.GetMerkleRoots()[sigchainSeqno] return root.Seqno, nil }
go
func merkleSeqnoAtGenerationInception(mctx libkb.MetaContext, teamchain *TeamSigChainState) (merkleSeqno keybase1.Seqno, err error) { ptk, err := teamchain.GetLatestPerTeamKey() if err != nil { return 0, err } sigchainSeqno := ptk.Seqno root := teamchain.GetMerkleRoots()[sigchainSeqno] return root.Seqno, nil }
[ "func", "merkleSeqnoAtGenerationInception", "(", "mctx", "libkb", ".", "MetaContext", ",", "teamchain", "*", "TeamSigChainState", ")", "(", "merkleSeqno", "keybase1", ".", "Seqno", ",", "err", "error", ")", "{", "ptk", ",", "err", ":=", "teamchain", ".", "GetLatestPerTeamKey", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "sigchainSeqno", ":=", "ptk", ".", "Seqno", "\n", "root", ":=", "teamchain", ".", "GetMerkleRoots", "(", ")", "[", "sigchainSeqno", "]", "\n", "return", "root", ".", "Seqno", ",", "nil", "\n", "}" ]
// merkleSeqnoAtGenerationInception assumes TeamSigChainState.MerkleRoots is populated
[ "merkleSeqnoAtGenerationInception", "assumes", "TeamSigChainState", ".", "MerkleRoots", "is", "populated" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/box_audit.go#L971-L979
161,307
keybase/client
go/client/help.go
init
func init() { cli.AppHelpTemplate = AppHelpTemplate cli.CommandHelpTemplate = CommandHelpTemplate cli.SubcommandHelpTemplate = SubcommandHelpTemplate }
go
func init() { cli.AppHelpTemplate = AppHelpTemplate cli.CommandHelpTemplate = CommandHelpTemplate cli.SubcommandHelpTemplate = SubcommandHelpTemplate }
[ "func", "init", "(", ")", "{", "cli", ".", "AppHelpTemplate", "=", "AppHelpTemplate", "\n", "cli", ".", "CommandHelpTemplate", "=", "CommandHelpTemplate", "\n", "cli", ".", "SubcommandHelpTemplate", "=", "SubcommandHelpTemplate", "\n", "}" ]
// Custom help templates for cli package
[ "Custom", "help", "templates", "for", "cli", "package" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/help.go#L169-L173
161,308
keybase/client
go/teams/chain_parse.go
ParseTeamChainLink
func ParseTeamChainLink(link string) (res SCChainLink, err error) { err = json.Unmarshal([]byte(link), &res) return res, err }
go
func ParseTeamChainLink(link string) (res SCChainLink, err error) { err = json.Unmarshal([]byte(link), &res) return res, err }
[ "func", "ParseTeamChainLink", "(", "link", "string", ")", "(", "res", "SCChainLink", ",", "err", "error", ")", "{", "err", "=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "link", ")", ",", "&", "res", ")", "\n", "return", "res", ",", "err", "\n", "}" ]
// Parse a chain link from a string. Just parses, does not validate.
[ "Parse", "a", "chain", "link", "from", "a", "string", ".", "Just", "parses", "does", "not", "validate", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/teams/chain_parse.go#L213-L216
161,309
keybase/client
go/engine/common.go
findDeviceKeys
func findDeviceKeys(m libkb.MetaContext, me *libkb.User) (*libkb.DeviceWithKeys, error) { // need to be logged in to get a device key (unlocked) lin, _ := isLoggedIn(m) if !lin { return nil, libkb.LoginRequiredError{} } // Get unlocked device for decryption and signing // passing in nil SecretUI since we don't know the passphrase. m.Debug("findDeviceKeys: getting device encryption key") parg := libkb.SecretKeyPromptArg{ Ska: libkb.SecretKeyArg{ Me: me, KeyType: libkb.DeviceEncryptionKeyType, }, Reason: "change passphrase", } encKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg) if err != nil { return nil, err } m.Debug("findDeviceKeys: got device encryption key") m.Debug("findDeviceKeys: getting device signing key") parg.Ska.KeyType = libkb.DeviceSigningKeyType sigKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg) if err != nil { return nil, err } m.Debug("findDeviceKeys: got device signing key") return libkb.NewDeviceWithKeysOnly(sigKey, encKey), nil }
go
func findDeviceKeys(m libkb.MetaContext, me *libkb.User) (*libkb.DeviceWithKeys, error) { // need to be logged in to get a device key (unlocked) lin, _ := isLoggedIn(m) if !lin { return nil, libkb.LoginRequiredError{} } // Get unlocked device for decryption and signing // passing in nil SecretUI since we don't know the passphrase. m.Debug("findDeviceKeys: getting device encryption key") parg := libkb.SecretKeyPromptArg{ Ska: libkb.SecretKeyArg{ Me: me, KeyType: libkb.DeviceEncryptionKeyType, }, Reason: "change passphrase", } encKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg) if err != nil { return nil, err } m.Debug("findDeviceKeys: got device encryption key") m.Debug("findDeviceKeys: getting device signing key") parg.Ska.KeyType = libkb.DeviceSigningKeyType sigKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, parg) if err != nil { return nil, err } m.Debug("findDeviceKeys: got device signing key") return libkb.NewDeviceWithKeysOnly(sigKey, encKey), nil }
[ "func", "findDeviceKeys", "(", "m", "libkb", ".", "MetaContext", ",", "me", "*", "libkb", ".", "User", ")", "(", "*", "libkb", ".", "DeviceWithKeys", ",", "error", ")", "{", "// need to be logged in to get a device key (unlocked)", "lin", ",", "_", ":=", "isLoggedIn", "(", "m", ")", "\n", "if", "!", "lin", "{", "return", "nil", ",", "libkb", ".", "LoginRequiredError", "{", "}", "\n", "}", "\n\n", "// Get unlocked device for decryption and signing", "// passing in nil SecretUI since we don't know the passphrase.", "m", ".", "Debug", "(", "\"", "\"", ")", "\n", "parg", ":=", "libkb", ".", "SecretKeyPromptArg", "{", "Ska", ":", "libkb", ".", "SecretKeyArg", "{", "Me", ":", "me", ",", "KeyType", ":", "libkb", ".", "DeviceEncryptionKeyType", ",", "}", ",", "Reason", ":", "\"", "\"", ",", "}", "\n", "encKey", ",", "err", ":=", "m", ".", "G", "(", ")", ".", "Keyrings", ".", "GetSecretKeyWithPrompt", "(", "m", ",", "parg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "m", ".", "Debug", "(", "\"", "\"", ")", "\n", "m", ".", "Debug", "(", "\"", "\"", ")", "\n", "parg", ".", "Ska", ".", "KeyType", "=", "libkb", ".", "DeviceSigningKeyType", "\n", "sigKey", ",", "err", ":=", "m", ".", "G", "(", ")", ".", "Keyrings", ".", "GetSecretKeyWithPrompt", "(", "m", ",", "parg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "m", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "return", "libkb", ".", "NewDeviceWithKeysOnly", "(", "sigKey", ",", "encKey", ")", ",", "nil", "\n", "}" ]
// findDeviceKeys looks for device keys and unlocks them.
[ "findDeviceKeys", "looks", "for", "device", "keys", "and", "unlocks", "them", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/common.go#L13-L44
161,310
keybase/client
go/engine/common.go
matchPaperKey
func matchPaperKey(m libkb.MetaContext, me *libkb.User, paper string) (*libkb.DeviceWithKeys, error) { cki := me.GetComputedKeyInfos() if cki == nil { return nil, fmt.Errorf("no computed key infos") } bdevs := cki.PaperDevices() if len(bdevs) == 0 { return nil, libkb.NoPaperKeysError{} } pc := new(libkb.PaperChecker) if err := pc.Check(m, paper); err != nil { return nil, err } // phrase has the correct version and contains valid words paperPhrase := libkb.NewPaperKeyPhrase(paper) bkarg := &PaperKeyGenArg{ Passphrase: paperPhrase, SkipPush: true, Me: me, } bkeng := NewPaperKeyGen(m.G(), bkarg) if err := RunEngine2(m, bkeng); err != nil { return nil, err } sigKey := bkeng.SigKey() encKey := bkeng.EncKey() var device *libkb.Device m.Debug("generated paper key signing kid: %s", sigKey.GetKID()) m.Debug("generated paper key encryption kid: %s", encKey.GetKID()) ckf := me.GetComputedKeyFamily() for _, bdev := range bdevs { sk, err := ckf.GetSibkeyForDevice(bdev.ID) if err != nil { m.Debug("ckf.GetSibkeyForDevice(%s) error: %s", bdev.ID, err) continue } m.Debug("paper key device %s signing kid: %s", bdev.ID, sk.GetKID()) ek, err := ckf.GetEncryptionSubkeyForDevice(bdev.ID) if err != nil { m.Debug("ckf.GetEncryptionSubkeyForDevice(%s) error: %s", bdev.ID, err) continue } m.Debug("paper key device %s encryption kid: %s", bdev.ID, ek.GetKID()) if sk.GetKID().Equal(sigKey.GetKID()) && ek.GetKID().Equal(encKey.GetKID()) { m.Debug("paper key device %s matches generated paper key", bdev.ID) device = bdev break } m.Debug("paper key device %s does not match generated paper key", bdev.ID) } if device == nil { m.Debug("no matching paper keys found") return nil, libkb.PassphraseError{Msg: "no matching paper backup keys found"} } var deviceName string if device.Description != nil { deviceName = *device.Description } return libkb.NewDeviceWithKeys(sigKey, encKey, device.ID, deviceName), nil }
go
func matchPaperKey(m libkb.MetaContext, me *libkb.User, paper string) (*libkb.DeviceWithKeys, error) { cki := me.GetComputedKeyInfos() if cki == nil { return nil, fmt.Errorf("no computed key infos") } bdevs := cki.PaperDevices() if len(bdevs) == 0 { return nil, libkb.NoPaperKeysError{} } pc := new(libkb.PaperChecker) if err := pc.Check(m, paper); err != nil { return nil, err } // phrase has the correct version and contains valid words paperPhrase := libkb.NewPaperKeyPhrase(paper) bkarg := &PaperKeyGenArg{ Passphrase: paperPhrase, SkipPush: true, Me: me, } bkeng := NewPaperKeyGen(m.G(), bkarg) if err := RunEngine2(m, bkeng); err != nil { return nil, err } sigKey := bkeng.SigKey() encKey := bkeng.EncKey() var device *libkb.Device m.Debug("generated paper key signing kid: %s", sigKey.GetKID()) m.Debug("generated paper key encryption kid: %s", encKey.GetKID()) ckf := me.GetComputedKeyFamily() for _, bdev := range bdevs { sk, err := ckf.GetSibkeyForDevice(bdev.ID) if err != nil { m.Debug("ckf.GetSibkeyForDevice(%s) error: %s", bdev.ID, err) continue } m.Debug("paper key device %s signing kid: %s", bdev.ID, sk.GetKID()) ek, err := ckf.GetEncryptionSubkeyForDevice(bdev.ID) if err != nil { m.Debug("ckf.GetEncryptionSubkeyForDevice(%s) error: %s", bdev.ID, err) continue } m.Debug("paper key device %s encryption kid: %s", bdev.ID, ek.GetKID()) if sk.GetKID().Equal(sigKey.GetKID()) && ek.GetKID().Equal(encKey.GetKID()) { m.Debug("paper key device %s matches generated paper key", bdev.ID) device = bdev break } m.Debug("paper key device %s does not match generated paper key", bdev.ID) } if device == nil { m.Debug("no matching paper keys found") return nil, libkb.PassphraseError{Msg: "no matching paper backup keys found"} } var deviceName string if device.Description != nil { deviceName = *device.Description } return libkb.NewDeviceWithKeys(sigKey, encKey, device.ID, deviceName), nil }
[ "func", "matchPaperKey", "(", "m", "libkb", ".", "MetaContext", ",", "me", "*", "libkb", ".", "User", ",", "paper", "string", ")", "(", "*", "libkb", ".", "DeviceWithKeys", ",", "error", ")", "{", "cki", ":=", "me", ".", "GetComputedKeyInfos", "(", ")", "\n", "if", "cki", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "bdevs", ":=", "cki", ".", "PaperDevices", "(", ")", "\n", "if", "len", "(", "bdevs", ")", "==", "0", "{", "return", "nil", ",", "libkb", ".", "NoPaperKeysError", "{", "}", "\n", "}", "\n\n", "pc", ":=", "new", "(", "libkb", ".", "PaperChecker", ")", "\n", "if", "err", ":=", "pc", ".", "Check", "(", "m", ",", "paper", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// phrase has the correct version and contains valid words", "paperPhrase", ":=", "libkb", ".", "NewPaperKeyPhrase", "(", "paper", ")", "\n\n", "bkarg", ":=", "&", "PaperKeyGenArg", "{", "Passphrase", ":", "paperPhrase", ",", "SkipPush", ":", "true", ",", "Me", ":", "me", ",", "}", "\n", "bkeng", ":=", "NewPaperKeyGen", "(", "m", ".", "G", "(", ")", ",", "bkarg", ")", "\n", "if", "err", ":=", "RunEngine2", "(", "m", ",", "bkeng", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "sigKey", ":=", "bkeng", ".", "SigKey", "(", ")", "\n", "encKey", ":=", "bkeng", ".", "EncKey", "(", ")", "\n", "var", "device", "*", "libkb", ".", "Device", "\n\n", "m", ".", "Debug", "(", "\"", "\"", ",", "sigKey", ".", "GetKID", "(", ")", ")", "\n", "m", ".", "Debug", "(", "\"", "\"", ",", "encKey", ".", "GetKID", "(", ")", ")", "\n\n", "ckf", ":=", "me", ".", "GetComputedKeyFamily", "(", ")", "\n", "for", "_", ",", "bdev", ":=", "range", "bdevs", "{", "sk", ",", "err", ":=", "ckf", ".", "GetSibkeyForDevice", "(", "bdev", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ",", "sk", ".", "GetKID", "(", ")", ")", "\n", "ek", ",", "err", ":=", "ckf", ".", "GetEncryptionSubkeyForDevice", "(", "bdev", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ",", "ek", ".", "GetKID", "(", ")", ")", "\n\n", "if", "sk", ".", "GetKID", "(", ")", ".", "Equal", "(", "sigKey", ".", "GetKID", "(", ")", ")", "&&", "ek", ".", "GetKID", "(", ")", ".", "Equal", "(", "encKey", ".", "GetKID", "(", ")", ")", "{", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ")", "\n", "device", "=", "bdev", "\n", "break", "\n", "}", "\n\n", "m", ".", "Debug", "(", "\"", "\"", ",", "bdev", ".", "ID", ")", "\n", "}", "\n\n", "if", "device", "==", "nil", "{", "m", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", ",", "libkb", ".", "PassphraseError", "{", "Msg", ":", "\"", "\"", "}", "\n", "}", "\n\n", "var", "deviceName", "string", "\n", "if", "device", ".", "Description", "!=", "nil", "{", "deviceName", "=", "*", "device", ".", "Description", "\n", "}", "\n", "return", "libkb", ".", "NewDeviceWithKeys", "(", "sigKey", ",", "encKey", ",", "device", ".", "ID", ",", "deviceName", ")", ",", "nil", "\n", "}" ]
// matchPaperKey checks to make sure paper is a valid paper phrase and that it exists // in the user's keyfamily.
[ "matchPaperKey", "checks", "to", "make", "sure", "paper", "is", "a", "valid", "paper", "phrase", "and", "that", "it", "exists", "in", "the", "user", "s", "keyfamily", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/common.go#L70-L140
161,311
keybase/client
go/engine/common.go
fetchLKS
func fetchLKS(m libkb.MetaContext, encKey libkb.GenericKey) (libkb.PassphraseGeneration, libkb.LKSecClientHalf, error) { arg := libkb.APIArg{ Endpoint: "passphrase/recover", SessionType: libkb.APISessionTypeREQUIRED, Args: libkb.HTTPArgs{ "kid": encKey.GetKID(), }, } res, err := m.G().API.Get(m, arg) var dummy libkb.LKSecClientHalf if err != nil { return 0, dummy, err } ctext, err := res.Body.AtKey("ctext").GetString() if err != nil { return 0, dummy, err } ppGen, err := res.Body.AtKey("passphrase_generation").GetInt() if err != nil { return 0, dummy, err } // Now try to decrypt with the unlocked device key msg, _, err := encKey.DecryptFromString(ctext) if err != nil { return 0, dummy, err } clientHalf, err := libkb.NewLKSecClientHalfFromBytes(msg) if err != nil { return 0, dummy, err } return libkb.PassphraseGeneration(ppGen), clientHalf, nil }
go
func fetchLKS(m libkb.MetaContext, encKey libkb.GenericKey) (libkb.PassphraseGeneration, libkb.LKSecClientHalf, error) { arg := libkb.APIArg{ Endpoint: "passphrase/recover", SessionType: libkb.APISessionTypeREQUIRED, Args: libkb.HTTPArgs{ "kid": encKey.GetKID(), }, } res, err := m.G().API.Get(m, arg) var dummy libkb.LKSecClientHalf if err != nil { return 0, dummy, err } ctext, err := res.Body.AtKey("ctext").GetString() if err != nil { return 0, dummy, err } ppGen, err := res.Body.AtKey("passphrase_generation").GetInt() if err != nil { return 0, dummy, err } // Now try to decrypt with the unlocked device key msg, _, err := encKey.DecryptFromString(ctext) if err != nil { return 0, dummy, err } clientHalf, err := libkb.NewLKSecClientHalfFromBytes(msg) if err != nil { return 0, dummy, err } return libkb.PassphraseGeneration(ppGen), clientHalf, nil }
[ "func", "fetchLKS", "(", "m", "libkb", ".", "MetaContext", ",", "encKey", "libkb", ".", "GenericKey", ")", "(", "libkb", ".", "PassphraseGeneration", ",", "libkb", ".", "LKSecClientHalf", ",", "error", ")", "{", "arg", ":=", "libkb", ".", "APIArg", "{", "Endpoint", ":", "\"", "\"", ",", "SessionType", ":", "libkb", ".", "APISessionTypeREQUIRED", ",", "Args", ":", "libkb", ".", "HTTPArgs", "{", "\"", "\"", ":", "encKey", ".", "GetKID", "(", ")", ",", "}", ",", "}", "\n", "res", ",", "err", ":=", "m", ".", "G", "(", ")", ".", "API", ".", "Get", "(", "m", ",", "arg", ")", "\n", "var", "dummy", "libkb", ".", "LKSecClientHalf", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "dummy", ",", "err", "\n", "}", "\n", "ctext", ",", "err", ":=", "res", ".", "Body", ".", "AtKey", "(", "\"", "\"", ")", ".", "GetString", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "dummy", ",", "err", "\n", "}", "\n", "ppGen", ",", "err", ":=", "res", ".", "Body", ".", "AtKey", "(", "\"", "\"", ")", ".", "GetInt", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "dummy", ",", "err", "\n", "}", "\n\n", "// Now try to decrypt with the unlocked device key", "msg", ",", "_", ",", "err", ":=", "encKey", ".", "DecryptFromString", "(", "ctext", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "dummy", ",", "err", "\n", "}", "\n", "clientHalf", ",", "err", ":=", "libkb", ".", "NewLKSecClientHalfFromBytes", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "dummy", ",", "err", "\n", "}", "\n\n", "return", "libkb", ".", "PassphraseGeneration", "(", "ppGen", ")", ",", "clientHalf", ",", "nil", "\n", "}" ]
// fetchLKS gets the encrypted LKS client half from the server. // It uses encKey to decrypt it. It also returns the passphrase // generation.
[ "fetchLKS", "gets", "the", "encrypted", "LKS", "client", "half", "from", "the", "server", ".", "It", "uses", "encKey", "to", "decrypt", "it", ".", "It", "also", "returns", "the", "passphrase", "generation", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/common.go#L145-L178
161,312
keybase/client
go/chat/signencrypt/codec.go
NewEncodingReader
func NewEncodingReader(encKey SecretboxKey, signKey SignKey, signaturePrefix kbcrypto.SignaturePrefix, nonce Nonce, innerReader io.Reader) io.Reader { return &codecReadWrapper{ innerReader: innerReader, codec: &encoderCodecShim{NewEncoder(encKey, signKey, signaturePrefix, nonce)}, } }
go
func NewEncodingReader(encKey SecretboxKey, signKey SignKey, signaturePrefix kbcrypto.SignaturePrefix, nonce Nonce, innerReader io.Reader) io.Reader { return &codecReadWrapper{ innerReader: innerReader, codec: &encoderCodecShim{NewEncoder(encKey, signKey, signaturePrefix, nonce)}, } }
[ "func", "NewEncodingReader", "(", "encKey", "SecretboxKey", ",", "signKey", "SignKey", ",", "signaturePrefix", "kbcrypto", ".", "SignaturePrefix", ",", "nonce", "Nonce", ",", "innerReader", "io", ".", "Reader", ")", "io", ".", "Reader", "{", "return", "&", "codecReadWrapper", "{", "innerReader", ":", "innerReader", ",", "codec", ":", "&", "encoderCodecShim", "{", "NewEncoder", "(", "encKey", ",", "signKey", ",", "signaturePrefix", ",", "nonce", ")", "}", ",", "}", "\n", "}" ]
// NewEncodingReader creates a new streaming encoder. // The signaturePrefix argument must not contain the null container.
[ "NewEncodingReader", "creates", "a", "new", "streaming", "encoder", ".", "The", "signaturePrefix", "argument", "must", "not", "contain", "the", "null", "container", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/signencrypt/codec.go#L476-L481
161,313
keybase/client
go/chat/signencrypt/codec.go
SealWhole
func SealWhole(plaintext []byte, encKey SecretboxKey, signKey SignKey, signaturePrefix kbcrypto.SignaturePrefix, nonce Nonce) []byte { encoder := NewEncoder(encKey, signKey, signaturePrefix, nonce) output := encoder.Write(plaintext) output = append(output, encoder.Finish()...) return output }
go
func SealWhole(plaintext []byte, encKey SecretboxKey, signKey SignKey, signaturePrefix kbcrypto.SignaturePrefix, nonce Nonce) []byte { encoder := NewEncoder(encKey, signKey, signaturePrefix, nonce) output := encoder.Write(plaintext) output = append(output, encoder.Finish()...) return output }
[ "func", "SealWhole", "(", "plaintext", "[", "]", "byte", ",", "encKey", "SecretboxKey", ",", "signKey", "SignKey", ",", "signaturePrefix", "kbcrypto", ".", "SignaturePrefix", ",", "nonce", "Nonce", ")", "[", "]", "byte", "{", "encoder", ":=", "NewEncoder", "(", "encKey", ",", "signKey", ",", "signaturePrefix", ",", "nonce", ")", "\n", "output", ":=", "encoder", ".", "Write", "(", "plaintext", ")", "\n", "output", "=", "append", "(", "output", ",", "encoder", ".", "Finish", "(", ")", "...", ")", "\n", "return", "output", "\n", "}" ]
// SealWhole seals all at once using the streaming encoding.
[ "SealWhole", "seals", "all", "at", "once", "using", "the", "streaming", "encoding", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/signencrypt/codec.go#L548-L553
161,314
keybase/client
go/kbfs/kbfshash/hash.go
DoRawDefaultHash
func DoRawDefaultHash(p []byte) (HashType, RawDefaultHash) { return DefaultHashType, RawDefaultHash(sha256.Sum256(p)) }
go
func DoRawDefaultHash(p []byte) (HashType, RawDefaultHash) { return DefaultHashType, RawDefaultHash(sha256.Sum256(p)) }
[ "func", "DoRawDefaultHash", "(", "p", "[", "]", "byte", ")", "(", "HashType", ",", "RawDefaultHash", ")", "{", "return", "DefaultHashType", ",", "RawDefaultHash", "(", "sha256", ".", "Sum256", "(", "p", ")", ")", "\n", "}" ]
// DoRawDefaultHash computes the default keybase hash of the given // data, and returns the type and the raw hash bytes.
[ "DoRawDefaultHash", "computes", "the", "default", "keybase", "hash", "of", "the", "given", "data", "and", "returns", "the", "type", "and", "the", "raw", "hash", "bytes", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L97-L99
161,315
keybase/client
go/kbfs/kbfshash/hash.go
Copy
func (rdh *RawDefaultHash) Copy() *RawDefaultHash { if rdh == nil { return nil } hashCopy := RawDefaultHash{} copy(hashCopy[:], rdh[:]) return &hashCopy }
go
func (rdh *RawDefaultHash) Copy() *RawDefaultHash { if rdh == nil { return nil } hashCopy := RawDefaultHash{} copy(hashCopy[:], rdh[:]) return &hashCopy }
[ "func", "(", "rdh", "*", "RawDefaultHash", ")", "Copy", "(", ")", "*", "RawDefaultHash", "{", "if", "rdh", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "hashCopy", ":=", "RawDefaultHash", "{", "}", "\n", "copy", "(", "hashCopy", "[", ":", "]", ",", "rdh", "[", ":", "]", ")", "\n", "return", "&", "hashCopy", "\n", "}" ]
// Copy returns a copied RawDefaultHash
[ "Copy", "returns", "a", "copied", "RawDefaultHash" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L102-L109
161,316
keybase/client
go/kbfs/kbfshash/hash.go
HashFromRaw
func HashFromRaw(hashType HashType, rawHash []byte) (Hash, error) { return HashFromBytes(append([]byte{byte(hashType)}, rawHash...)) }
go
func HashFromRaw(hashType HashType, rawHash []byte) (Hash, error) { return HashFromBytes(append([]byte{byte(hashType)}, rawHash...)) }
[ "func", "HashFromRaw", "(", "hashType", "HashType", ",", "rawHash", "[", "]", "byte", ")", "(", "Hash", ",", "error", ")", "{", "return", "HashFromBytes", "(", "append", "(", "[", "]", "byte", "{", "byte", "(", "hashType", ")", "}", ",", "rawHash", "...", ")", ")", "\n", "}" ]
// HashFromRaw creates a hash from a type and raw hash data. If the // returned error is nil, the returned Hash is valid.
[ "HashFromRaw", "creates", "a", "hash", "from", "a", "type", "and", "raw", "hash", "data", ".", "If", "the", "returned", "error", "is", "nil", "the", "returned", "Hash", "is", "valid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L125-L127
161,317
keybase/client
go/kbfs/kbfshash/hash.go
HashFromBytes
func HashFromBytes(data []byte) (Hash, error) { h := Hash{string(data)} if !h.IsValid() { return Hash{}, errors.WithStack(InvalidHashError{h}) } return h, nil }
go
func HashFromBytes(data []byte) (Hash, error) { h := Hash{string(data)} if !h.IsValid() { return Hash{}, errors.WithStack(InvalidHashError{h}) } return h, nil }
[ "func", "HashFromBytes", "(", "data", "[", "]", "byte", ")", "(", "Hash", ",", "error", ")", "{", "h", ":=", "Hash", "{", "string", "(", "data", ")", "}", "\n", "if", "!", "h", ".", "IsValid", "(", ")", "{", "return", "Hash", "{", "}", ",", "errors", ".", "WithStack", "(", "InvalidHashError", "{", "h", "}", ")", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}" ]
// HashFromBytes creates a hash from the given byte array. If the // returned error is nil, the returned Hash is valid.
[ "HashFromBytes", "creates", "a", "hash", "from", "the", "given", "byte", "array", ".", "If", "the", "returned", "error", "is", "nil", "the", "returned", "Hash", "is", "valid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L131-L137
161,318
keybase/client
go/kbfs/kbfshash/hash.go
HashFromString
func HashFromString(dataStr string) (Hash, error) { data, err := hex.DecodeString(dataStr) if err != nil { return Hash{}, errors.WithStack(err) } return HashFromBytes(data) }
go
func HashFromString(dataStr string) (Hash, error) { data, err := hex.DecodeString(dataStr) if err != nil { return Hash{}, errors.WithStack(err) } return HashFromBytes(data) }
[ "func", "HashFromString", "(", "dataStr", "string", ")", "(", "Hash", ",", "error", ")", "{", "data", ",", "err", ":=", "hex", ".", "DecodeString", "(", "dataStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Hash", "{", "}", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "HashFromBytes", "(", "data", ")", "\n", "}" ]
// HashFromString creates a hash from the given string. If the // returned error is nil, the returned Hash is valid.
[ "HashFromString", "creates", "a", "hash", "from", "the", "given", "string", ".", "If", "the", "returned", "error", "is", "nil", "the", "returned", "Hash", "is", "valid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L141-L147
161,319
keybase/client
go/kbfs/kbfshash/hash.go
DefaultHash
func DefaultHash(buf []byte) (Hash, error) { hashType, rawHash := DoRawDefaultHash(buf) return HashFromRaw(hashType, rawHash[:]) }
go
func DefaultHash(buf []byte) (Hash, error) { hashType, rawHash := DoRawDefaultHash(buf) return HashFromRaw(hashType, rawHash[:]) }
[ "func", "DefaultHash", "(", "buf", "[", "]", "byte", ")", "(", "Hash", ",", "error", ")", "{", "hashType", ",", "rawHash", ":=", "DoRawDefaultHash", "(", "buf", ")", "\n", "return", "HashFromRaw", "(", "hashType", ",", "rawHash", "[", ":", "]", ")", "\n", "}" ]
// DefaultHash computes the hash of the given data with the default // hash type.
[ "DefaultHash", "computes", "the", "hash", "of", "the", "given", "data", "with", "the", "default", "hash", "type", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L151-L154
161,320
keybase/client
go/kbfs/kbfshash/hash.go
DoHash
func DoHash(buf []byte, ht HashType) (Hash, error) { switch ht { case SHA256Hash, SHA256HashV2: default: return Hash{}, errors.WithStack(UnknownHashTypeError{ht}) } _, rawHash := DoRawDefaultHash(buf) return HashFromRaw(ht, rawHash[:]) }
go
func DoHash(buf []byte, ht HashType) (Hash, error) { switch ht { case SHA256Hash, SHA256HashV2: default: return Hash{}, errors.WithStack(UnknownHashTypeError{ht}) } _, rawHash := DoRawDefaultHash(buf) return HashFromRaw(ht, rawHash[:]) }
[ "func", "DoHash", "(", "buf", "[", "]", "byte", ",", "ht", "HashType", ")", "(", "Hash", ",", "error", ")", "{", "switch", "ht", "{", "case", "SHA256Hash", ",", "SHA256HashV2", ":", "default", ":", "return", "Hash", "{", "}", ",", "errors", ".", "WithStack", "(", "UnknownHashTypeError", "{", "ht", "}", ")", "\n", "}", "\n", "_", ",", "rawHash", ":=", "DoRawDefaultHash", "(", "buf", ")", "\n", "return", "HashFromRaw", "(", "ht", ",", "rawHash", "[", ":", "]", ")", "\n", "}" ]
// DoHash computes the hash of the given data with the given hash // type.
[ "DoHash", "computes", "the", "hash", "of", "the", "given", "data", "with", "the", "given", "hash", "type", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L158-L166
161,321
keybase/client
go/kbfs/kbfshash/hash.go
IsValid
func (h Hash) IsValid() bool { if len(h.h) < MinHashByteLength { return false } if len(h.h) > MaxHashByteLength { return false } if h.hashType() == InvalidHash { return false } return true }
go
func (h Hash) IsValid() bool { if len(h.h) < MinHashByteLength { return false } if len(h.h) > MaxHashByteLength { return false } if h.hashType() == InvalidHash { return false } return true }
[ "func", "(", "h", "Hash", ")", "IsValid", "(", ")", "bool", "{", "if", "len", "(", "h", ".", "h", ")", "<", "MinHashByteLength", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "h", ".", "h", ")", ">", "MaxHashByteLength", "{", "return", "false", "\n", "}", "\n\n", "if", "h", ".", "hashType", "(", ")", "==", "InvalidHash", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// IsValid returns whether the hash is valid. Note that a hash with an // unknown version is still valid.
[ "IsValid", "returns", "whether", "the", "hash", "is", "valid", ".", "Note", "that", "a", "hash", "with", "an", "unknown", "version", "is", "still", "valid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L183-L196
161,322
keybase/client
go/kbfs/kbfshash/hash.go
MarshalBinary
func (h Hash) MarshalBinary() (data []byte, err error) { if h == (Hash{}) { return nil, nil } if !h.IsValid() { return nil, errors.WithStack(InvalidHashError{h}) } return []byte(h.h), nil }
go
func (h Hash) MarshalBinary() (data []byte, err error) { if h == (Hash{}) { return nil, nil } if !h.IsValid() { return nil, errors.WithStack(InvalidHashError{h}) } return []byte(h.h), nil }
[ "func", "(", "h", "Hash", ")", "MarshalBinary", "(", ")", "(", "data", "[", "]", "byte", ",", "err", "error", ")", "{", "if", "h", "==", "(", "Hash", "{", "}", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "if", "!", "h", ".", "IsValid", "(", ")", "{", "return", "nil", ",", "errors", ".", "WithStack", "(", "InvalidHashError", "{", "h", "}", ")", "\n", "}", "\n\n", "return", "[", "]", "byte", "(", "h", ".", "h", ")", ",", "nil", "\n", "}" ]
// MarshalBinary implements the encoding.BinaryMarshaler interface for // Hash. Returns an error if the hash is invalid and not the zero // hash.
[ "MarshalBinary", "implements", "the", "encoding", ".", "BinaryMarshaler", "interface", "for", "Hash", ".", "Returns", "an", "error", "if", "the", "hash", "is", "invalid", "and", "not", "the", "zero", "hash", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L210-L220
161,323
keybase/client
go/kbfs/kbfshash/hash.go
UnmarshalBinary
func (h *Hash) UnmarshalBinary(data []byte) error { if len(data) == 0 { *h = Hash{} return nil } h.h = string(data) if !h.IsValid() { err := InvalidHashError{*h} *h = Hash{} return errors.WithStack(err) } return nil }
go
func (h *Hash) UnmarshalBinary(data []byte) error { if len(data) == 0 { *h = Hash{} return nil } h.h = string(data) if !h.IsValid() { err := InvalidHashError{*h} *h = Hash{} return errors.WithStack(err) } return nil }
[ "func", "(", "h", "*", "Hash", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "data", ")", "==", "0", "{", "*", "h", "=", "Hash", "{", "}", "\n", "return", "nil", "\n", "}", "\n\n", "h", ".", "h", "=", "string", "(", "data", ")", "\n", "if", "!", "h", ".", "IsValid", "(", ")", "{", "err", ":=", "InvalidHashError", "{", "*", "h", "}", "\n", "*", "h", "=", "Hash", "{", "}", "\n", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface // for Hash. Returns an error if the given byte array is non-empty and // the hash is invalid.
[ "UnmarshalBinary", "implements", "the", "encoding", ".", "BinaryUnmarshaler", "interface", "for", "Hash", ".", "Returns", "an", "error", "if", "the", "given", "byte", "array", "is", "non", "-", "empty", "and", "the", "hash", "is", "invalid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L225-L239
161,324
keybase/client
go/kbfs/kbfshash/hash.go
Verify
func (h Hash) Verify(buf []byte) error { if !h.IsValid() { return errors.WithStack(InvalidHashError{h}) } expectedH, err := DoHash(buf, h.hashType()) if err != nil { return err } if h != expectedH { return errors.WithStack(HashMismatchError{expectedH, h}) } return nil }
go
func (h Hash) Verify(buf []byte) error { if !h.IsValid() { return errors.WithStack(InvalidHashError{h}) } expectedH, err := DoHash(buf, h.hashType()) if err != nil { return err } if h != expectedH { return errors.WithStack(HashMismatchError{expectedH, h}) } return nil }
[ "func", "(", "h", "Hash", ")", "Verify", "(", "buf", "[", "]", "byte", ")", "error", "{", "if", "!", "h", ".", "IsValid", "(", ")", "{", "return", "errors", ".", "WithStack", "(", "InvalidHashError", "{", "h", "}", ")", "\n", "}", "\n\n", "expectedH", ",", "err", ":=", "DoHash", "(", "buf", ",", "h", ".", "hashType", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "h", "!=", "expectedH", "{", "return", "errors", ".", "WithStack", "(", "HashMismatchError", "{", "expectedH", ",", "h", "}", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Verify makes sure that the hash matches the given data and returns // an error otherwise.
[ "Verify", "makes", "sure", "that", "the", "hash", "matches", "the", "given", "data", "and", "returns", "an", "error", "otherwise", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L243-L257
161,325
keybase/client
go/kbfs/kbfshash/hash.go
UnmarshalText
func (h *Hash) UnmarshalText(data []byte) error { newH, err := HashFromString(string(data)) if err != nil { return err } *h = newH return nil }
go
func (h *Hash) UnmarshalText(data []byte) error { newH, err := HashFromString(string(data)) if err != nil { return err } *h = newH return nil }
[ "func", "(", "h", "*", "Hash", ")", "UnmarshalText", "(", "data", "[", "]", "byte", ")", "error", "{", "newH", ",", "err", ":=", "HashFromString", "(", "string", "(", "data", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "h", "=", "newH", "\n", "return", "nil", "\n", "}" ]
// UnmarshalText implements the encoding.TextUnmarshaler interface // for Hash.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnmarshaler", "interface", "for", "Hash", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L267-L274
161,326
keybase/client
go/kbfs/kbfshash/hash.go
DefaultHMAC
func DefaultHMAC(key, buf []byte) (HMAC, error) { mac := hmac.New(DefaultHashNew, key) mac.Write(buf) h, err := HashFromRaw(DefaultHashType, mac.Sum(nil)) if err != nil { return HMAC{}, err } return HMAC{h}, nil }
go
func DefaultHMAC(key, buf []byte) (HMAC, error) { mac := hmac.New(DefaultHashNew, key) mac.Write(buf) h, err := HashFromRaw(DefaultHashType, mac.Sum(nil)) if err != nil { return HMAC{}, err } return HMAC{h}, nil }
[ "func", "DefaultHMAC", "(", "key", ",", "buf", "[", "]", "byte", ")", "(", "HMAC", ",", "error", ")", "{", "mac", ":=", "hmac", ".", "New", "(", "DefaultHashNew", ",", "key", ")", "\n", "mac", ".", "Write", "(", "buf", ")", "\n", "h", ",", "err", ":=", "HashFromRaw", "(", "DefaultHashType", ",", "mac", ".", "Sum", "(", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "HMAC", "{", "}", ",", "err", "\n", "}", "\n", "return", "HMAC", "{", "h", "}", ",", "nil", "\n", "}" ]
// DefaultHMAC computes the HMAC with the given key of the given data // using the default hash.
[ "DefaultHMAC", "computes", "the", "HMAC", "with", "the", "given", "key", "of", "the", "given", "data", "using", "the", "default", "hash", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L300-L308
161,327
keybase/client
go/kbfs/kbfshash/hash.go
MarshalBinary
func (hmac HMAC) MarshalBinary() (data []byte, err error) { return hmac.h.MarshalBinary() }
go
func (hmac HMAC) MarshalBinary() (data []byte, err error) { return hmac.h.MarshalBinary() }
[ "func", "(", "hmac", "HMAC", ")", "MarshalBinary", "(", ")", "(", "data", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "hmac", ".", "h", ".", "MarshalBinary", "(", ")", "\n", "}" ]
// MarshalBinary implements the encoding.BinaryMarshaler interface for // HMAC. Returns an error if the HMAC is invalid and not the zero // HMAC.
[ "MarshalBinary", "implements", "the", "encoding", ".", "BinaryMarshaler", "interface", "for", "HMAC", ".", "Returns", "an", "error", "if", "the", "HMAC", "is", "invalid", "and", "not", "the", "zero", "HMAC", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L336-L338
161,328
keybase/client
go/kbfs/kbfshash/hash.go
UnmarshalBinary
func (hmac *HMAC) UnmarshalBinary(data []byte) error { return hmac.h.UnmarshalBinary(data) }
go
func (hmac *HMAC) UnmarshalBinary(data []byte) error { return hmac.h.UnmarshalBinary(data) }
[ "func", "(", "hmac", "*", "HMAC", ")", "UnmarshalBinary", "(", "data", "[", "]", "byte", ")", "error", "{", "return", "hmac", ".", "h", ".", "UnmarshalBinary", "(", "data", ")", "\n", "}" ]
// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface // for HMAC. Returns an error if the given byte array is non-empty and // the HMAC is invalid.
[ "UnmarshalBinary", "implements", "the", "encoding", ".", "BinaryUnmarshaler", "interface", "for", "HMAC", ".", "Returns", "an", "error", "if", "the", "given", "byte", "array", "is", "non", "-", "empty", "and", "the", "HMAC", "is", "invalid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L343-L345
161,329
keybase/client
go/kbfs/kbfshash/hash.go
UnmarshalText
func (hmac *HMAC) UnmarshalText(data []byte) error { return hmac.h.UnmarshalText(data) }
go
func (hmac *HMAC) UnmarshalText(data []byte) error { return hmac.h.UnmarshalText(data) }
[ "func", "(", "hmac", "*", "HMAC", ")", "UnmarshalText", "(", "data", "[", "]", "byte", ")", "error", "{", "return", "hmac", ".", "h", ".", "UnmarshalText", "(", "data", ")", "\n", "}" ]
// UnmarshalText implements the encoding.TextUnmarshaler interface // for HMAC.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnmarshaler", "interface", "for", "HMAC", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L355-L357
161,330
keybase/client
go/kbfs/kbfshash/hash.go
Verify
func (hmac HMAC) Verify(key, buf []byte) error { if !hmac.IsValid() { return errors.WithStack(InvalidHashError{hmac.h}) } // Once we have multiple hash types we'll need to expand this. t := hmac.hashType() if t != DefaultHashType { return errors.WithStack(UnknownHashTypeError{t}) } expectedHMAC, err := DefaultHMAC(key, buf) if err != nil { return err } if hmac != expectedHMAC { return errors.WithStack( HashMismatchError{expectedHMAC.h, hmac.h}) } return nil }
go
func (hmac HMAC) Verify(key, buf []byte) error { if !hmac.IsValid() { return errors.WithStack(InvalidHashError{hmac.h}) } // Once we have multiple hash types we'll need to expand this. t := hmac.hashType() if t != DefaultHashType { return errors.WithStack(UnknownHashTypeError{t}) } expectedHMAC, err := DefaultHMAC(key, buf) if err != nil { return err } if hmac != expectedHMAC { return errors.WithStack( HashMismatchError{expectedHMAC.h, hmac.h}) } return nil }
[ "func", "(", "hmac", "HMAC", ")", "Verify", "(", "key", ",", "buf", "[", "]", "byte", ")", "error", "{", "if", "!", "hmac", ".", "IsValid", "(", ")", "{", "return", "errors", ".", "WithStack", "(", "InvalidHashError", "{", "hmac", ".", "h", "}", ")", "\n", "}", "\n\n", "// Once we have multiple hash types we'll need to expand this.", "t", ":=", "hmac", ".", "hashType", "(", ")", "\n", "if", "t", "!=", "DefaultHashType", "{", "return", "errors", ".", "WithStack", "(", "UnknownHashTypeError", "{", "t", "}", ")", "\n", "}", "\n\n", "expectedHMAC", ",", "err", ":=", "DefaultHMAC", "(", "key", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "hmac", "!=", "expectedHMAC", "{", "return", "errors", ".", "WithStack", "(", "HashMismatchError", "{", "expectedHMAC", ".", "h", ",", "hmac", ".", "h", "}", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Verify makes sure that the HMAC matches the given data.
[ "Verify", "makes", "sure", "that", "the", "HMAC", "matches", "the", "given", "data", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfshash/hash.go#L360-L380
161,331
keybase/client
go/kbfs/libfuse/sync_from_server_file.go
Write
func (f *SyncFromServerFile) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) (err error) { f.folder.fs.log.CDebugf(ctx, "SyncFromServerFile Write") defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() if len(req.Data) == 0 { return nil } folderBranch := f.folder.getFolderBranch() if folderBranch == (data.FolderBranch{}) { // Nothing to do. resp.Size = len(req.Data) return nil } // Use a context with a nil CtxAppIDKey value so that // notifications generated from this sync won't be discarded. syncCtx := context.WithValue(ctx, libfs.CtxAppIDKey, nil) err = f.folder.fs.config.KBFSOps().SyncFromServer( syncCtx, folderBranch, nil) if err != nil { return err } f.folder.fs.NotificationGroupWait() resp.Size = len(req.Data) return nil }
go
func (f *SyncFromServerFile) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) (err error) { f.folder.fs.log.CDebugf(ctx, "SyncFromServerFile Write") defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() if len(req.Data) == 0 { return nil } folderBranch := f.folder.getFolderBranch() if folderBranch == (data.FolderBranch{}) { // Nothing to do. resp.Size = len(req.Data) return nil } // Use a context with a nil CtxAppIDKey value so that // notifications generated from this sync won't be discarded. syncCtx := context.WithValue(ctx, libfs.CtxAppIDKey, nil) err = f.folder.fs.config.KBFSOps().SyncFromServer( syncCtx, folderBranch, nil) if err != nil { return err } f.folder.fs.NotificationGroupWait() resp.Size = len(req.Data) return nil }
[ "func", "(", "f", "*", "SyncFromServerFile", ")", "Write", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "WriteRequest", ",", "resp", "*", "fuse", ".", "WriteResponse", ")", "(", "err", "error", ")", "{", "f", ".", "folder", ".", "fs", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "f", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n", "if", "len", "(", "req", ".", "Data", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "folderBranch", ":=", "f", ".", "folder", ".", "getFolderBranch", "(", ")", "\n", "if", "folderBranch", "==", "(", "data", ".", "FolderBranch", "{", "}", ")", "{", "// Nothing to do.", "resp", ".", "Size", "=", "len", "(", "req", ".", "Data", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// Use a context with a nil CtxAppIDKey value so that", "// notifications generated from this sync won't be discarded.", "syncCtx", ":=", "context", ".", "WithValue", "(", "ctx", ",", "libfs", ".", "CtxAppIDKey", ",", "nil", ")", "\n", "err", "=", "f", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SyncFromServer", "(", "syncCtx", ",", "folderBranch", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "f", ".", "folder", ".", "fs", ".", "NotificationGroupWait", "(", ")", "\n", "resp", ".", "Size", "=", "len", "(", "req", ".", "Data", ")", "\n", "return", "nil", "\n", "}" ]
// Write implements the fs.HandleWriter interface for SyncFromServerFile.
[ "Write", "implements", "the", "fs", ".", "HandleWriter", "interface", "for", "SyncFromServerFile", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/sync_from_server_file.go#L47-L72
161,332
keybase/client
go/protocol/keybase1/rekey_ui.go
Refresh
func (c RekeyUIClient) Refresh(ctx context.Context, __arg RefreshArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.rekeyUI.refresh", []interface{}{__arg}, nil) return }
go
func (c RekeyUIClient) Refresh(ctx context.Context, __arg RefreshArg) (err error) { err = c.Cli.Call(ctx, "keybase.1.rekeyUI.refresh", []interface{}{__arg}, nil) return }
[ "func", "(", "c", "RekeyUIClient", ")", "Refresh", "(", "ctx", "context", ".", "Context", ",", "__arg", "RefreshArg", ")", "(", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "Call", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ")", "\n", "return", "\n", "}" ]
// Refresh is called whenever Electron should refresh the UI, either // because a change came in, or because there was a timeout poll.
[ "Refresh", "is", "called", "whenever", "Electron", "should", "refresh", "the", "UI", "either", "because", "a", "change", "came", "in", "or", "because", "there", "was", "a", "timeout", "poll", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey_ui.go#L152-L155
161,333
keybase/client
go/protocol/keybase1/rekey_ui.go
RekeySendEvent
func (c RekeyUIClient) RekeySendEvent(ctx context.Context, __arg RekeySendEventArg) (err error) { err = c.Cli.Notify(ctx, "keybase.1.rekeyUI.rekeySendEvent", []interface{}{__arg}) return }
go
func (c RekeyUIClient) RekeySendEvent(ctx context.Context, __arg RekeySendEventArg) (err error) { err = c.Cli.Notify(ctx, "keybase.1.rekeyUI.rekeySendEvent", []interface{}{__arg}) return }
[ "func", "(", "c", "RekeyUIClient", ")", "RekeySendEvent", "(", "ctx", "context", ".", "Context", ",", "__arg", "RekeySendEventArg", ")", "(", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "Notify", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ")", "\n", "return", "\n", "}" ]
// RekeySendEvent sends updates as to what's going on in the rekey // thread. This is mainly useful in testing.
[ "RekeySendEvent", "sends", "updates", "as", "to", "what", "s", "going", "on", "in", "the", "rekey", "thread", ".", "This", "is", "mainly", "useful", "in", "testing", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/keybase1/rekey_ui.go#L159-L162
161,334
keybase/client
go/kbfs/libfuse/dir.go
fillAttrWithUIDAndWritePerm
func (f *Folder) fillAttrWithUIDAndWritePerm( ctx context.Context, node libkbfs.Node, ei *data.EntryInfo, a *fuse.Attr) (err error) { a.Valid = 1 * time.Minute node.FillCacheDuration(&a.Valid) a.Size = ei.Size a.Blocks = getNumBlocksFromSize(ei.Size) a.Mtime = time.Unix(0, ei.Mtime) a.Ctime = time.Unix(0, ei.Ctime) a.Uid = uint32(os.Getuid()) if a.Mode, err = f.writePermMode(ctx, node, a.Mode); err != nil { return err } return nil }
go
func (f *Folder) fillAttrWithUIDAndWritePerm( ctx context.Context, node libkbfs.Node, ei *data.EntryInfo, a *fuse.Attr) (err error) { a.Valid = 1 * time.Minute node.FillCacheDuration(&a.Valid) a.Size = ei.Size a.Blocks = getNumBlocksFromSize(ei.Size) a.Mtime = time.Unix(0, ei.Mtime) a.Ctime = time.Unix(0, ei.Ctime) a.Uid = uint32(os.Getuid()) if a.Mode, err = f.writePermMode(ctx, node, a.Mode); err != nil { return err } return nil }
[ "func", "(", "f", "*", "Folder", ")", "fillAttrWithUIDAndWritePerm", "(", "ctx", "context", ".", "Context", ",", "node", "libkbfs", ".", "Node", ",", "ei", "*", "data", ".", "EntryInfo", ",", "a", "*", "fuse", ".", "Attr", ")", "(", "err", "error", ")", "{", "a", ".", "Valid", "=", "1", "*", "time", ".", "Minute", "\n", "node", ".", "FillCacheDuration", "(", "&", "a", ".", "Valid", ")", "\n\n", "a", ".", "Size", "=", "ei", ".", "Size", "\n", "a", ".", "Blocks", "=", "getNumBlocksFromSize", "(", "ei", ".", "Size", ")", "\n", "a", ".", "Mtime", "=", "time", ".", "Unix", "(", "0", ",", "ei", ".", "Mtime", ")", "\n", "a", ".", "Ctime", "=", "time", ".", "Unix", "(", "0", ",", "ei", ".", "Ctime", ")", "\n\n", "a", ".", "Uid", "=", "uint32", "(", "os", ".", "Getuid", "(", ")", ")", "\n\n", "if", "a", ".", "Mode", ",", "err", "=", "f", ".", "writePermMode", "(", "ctx", ",", "node", ",", "a", ".", "Mode", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// fillAttrWithUIDAndWritePerm sets attributes based on the entry info, and // pops in correct UID and write permissions. It only handles fields common to // all entryinfo types.
[ "fillAttrWithUIDAndWritePerm", "sets", "attributes", "based", "on", "the", "entry", "info", "and", "pops", "in", "correct", "UID", "and", "write", "permissions", ".", "It", "only", "handles", "fields", "common", "to", "all", "entryinfo", "types", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L374-L392
161,335
keybase/client
go/kbfs/libfuse/dir.go
Access
func (d *Dir) Access(ctx context.Context, r *fuse.AccessRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Access", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() return d.folder.access(ctx, r) }
go
func (d *Dir) Access(ctx context.Context, r *fuse.AccessRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Access", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() return d.folder.access(ctx, r) }
[ "func", "(", "d", "*", "Dir", ")", "Access", "(", "ctx", "context", ".", "Context", ",", "r", "*", "fuse", ".", "AccessRequest", ")", "(", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "return", "d", ".", "folder", ".", "access", "(", "ctx", ",", "r", ")", "\n", "}" ]
// Access implements the fs.NodeAccesser interface for File. See comment for // File.Access for more details.
[ "Access", "implements", "the", "fs", ".", "NodeAccesser", "interface", "for", "File", ".", "See", "comment", "for", "File", ".", "Access", "for", "more", "details", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L481-L487
161,336
keybase/client
go/kbfs/libfuse/dir.go
Attr
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Attr", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Attr") defer func() { err = d.folder.processError(ctx, libkbfs.ReadMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } return d.attr(ctx, a) }
go
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Attr", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Attr") defer func() { err = d.folder.processError(ctx, libkbfs.ReadMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } return d.attr(ctx, a) }
[ "func", "(", "d", "*", "Dir", ")", "Attr", "(", "ctx", "context", ".", "Context", ",", "a", "*", "fuse", ".", "Attr", ")", "(", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "ReadMode", ",", "err", ")", "}", "(", ")", "\n\n", "// This fits in situation 1 as described in libkbfs/delayed_cancellation.go", "err", "=", "libcontext", ".", "EnableDelayedCancellationWithGracePeriod", "(", "ctx", ",", "d", ".", "folder", ".", "fs", ".", "config", ".", "DelayedCancellationGracePeriod", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "d", ".", "attr", "(", "ctx", ",", "a", ")", "\n", "}" ]
// Attr implements the fs.Node interface for Dir.
[ "Attr", "implements", "the", "fs", ".", "Node", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L490-L506
161,337
keybase/client
go/kbfs/libfuse/dir.go
Create
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fs.Node, handle fs.Handle, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Create", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Create %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() isExec := (req.Mode.Perm() & 0100) != 0 excl := getEXCLFromCreateRequest(req) newNode, ei, err := d.folder.fs.config.KBFSOps().CreateFile( ctx, d.node, req.Name, isExec, excl) if err != nil { return nil, nil, err } child := d.makeFile(newNode) // Create is normally followed an Attr call. Fuse uses the same context for // them. If the context is cancelled after the Create call enters the // critical portion, and grace period has passed before Attr happens, the // Attr can result in EINTR which application does not expect. This caches // the EntryInfo for the created node and allows the subsequent Attr call to // use the cached EntryInfo instead of relying on a new Stat call. if reqID, ok := ctx.Value(CtxIDKey).(string); ok { child.eiCache.set(reqID, ei) } d.folder.nodesMu.Lock() d.folder.nodes[newNode.GetID()] = child d.folder.nodesMu.Unlock() return child, child, nil }
go
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fs.Node, handle fs.Handle, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Create", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Create %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() isExec := (req.Mode.Perm() & 0100) != 0 excl := getEXCLFromCreateRequest(req) newNode, ei, err := d.folder.fs.config.KBFSOps().CreateFile( ctx, d.node, req.Name, isExec, excl) if err != nil { return nil, nil, err } child := d.makeFile(newNode) // Create is normally followed an Attr call. Fuse uses the same context for // them. If the context is cancelled after the Create call enters the // critical portion, and grace period has passed before Attr happens, the // Attr can result in EINTR which application does not expect. This caches // the EntryInfo for the created node and allows the subsequent Attr call to // use the cached EntryInfo instead of relying on a new Stat call. if reqID, ok := ctx.Value(CtxIDKey).(string); ok { child.eiCache.set(reqID, ei) } d.folder.nodesMu.Lock() d.folder.nodes[newNode.GetID()] = child d.folder.nodesMu.Unlock() return child, child, nil }
[ "func", "(", "d", "*", "Dir", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "CreateRequest", ",", "resp", "*", "fuse", ".", "CreateResponse", ")", "(", "node", "fs", ".", "Node", ",", "handle", "fs", ".", "Handle", ",", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "req", ".", "Name", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "req", ".", "Name", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "isExec", ":=", "(", "req", ".", "Mode", ".", "Perm", "(", ")", "&", "0100", ")", "!=", "0", "\n", "excl", ":=", "getEXCLFromCreateRequest", "(", "req", ")", "\n", "newNode", ",", "ei", ",", "err", ":=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "CreateFile", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "Name", ",", "isExec", ",", "excl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "child", ":=", "d", ".", "makeFile", "(", "newNode", ")", "\n\n", "// Create is normally followed an Attr call. Fuse uses the same context for", "// them. If the context is cancelled after the Create call enters the", "// critical portion, and grace period has passed before Attr happens, the", "// Attr can result in EINTR which application does not expect. This caches", "// the EntryInfo for the created node and allows the subsequent Attr call to", "// use the cached EntryInfo instead of relying on a new Stat call.", "if", "reqID", ",", "ok", ":=", "ctx", ".", "Value", "(", "CtxIDKey", ")", ".", "(", "string", ")", ";", "ok", "{", "child", ".", "eiCache", ".", "set", "(", "reqID", ",", "ei", ")", "\n", "}", "\n\n", "d", ".", "folder", ".", "nodesMu", ".", "Lock", "(", ")", "\n", "d", ".", "folder", ".", "nodes", "[", "newNode", ".", "GetID", "(", ")", "]", "=", "child", "\n", "d", ".", "folder", ".", "nodesMu", ".", "Unlock", "(", ")", "\n", "return", "child", ",", "child", ",", "nil", "\n", "}" ]
// Create implements the fs.NodeCreater interface for Dir.
[ "Create", "implements", "the", "fs", ".", "NodeCreater", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L626-L658
161,338
keybase/client
go/kbfs/libfuse/dir.go
Mkdir
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) ( node fs.Node, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Mkdir", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Mkdir %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return nil, err } newNode, _, err := d.folder.fs.config.KBFSOps().CreateDir( ctx, d.node, req.Name) if err != nil { return nil, err } child := newDir(d.folder, newNode) d.folder.nodesMu.Lock() d.folder.nodes[newNode.GetID()] = child d.folder.nodesMu.Unlock() return child, nil }
go
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) ( node fs.Node, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Mkdir", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Mkdir %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return nil, err } newNode, _, err := d.folder.fs.config.KBFSOps().CreateDir( ctx, d.node, req.Name) if err != nil { return nil, err } child := newDir(d.folder, newNode) d.folder.nodesMu.Lock() d.folder.nodes[newNode.GetID()] = child d.folder.nodesMu.Unlock() return child, nil }
[ "func", "(", "d", "*", "Dir", ")", "Mkdir", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "MkdirRequest", ")", "(", "node", "fs", ".", "Node", ",", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "req", ".", "Name", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "req", ".", "Name", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "// This fits in situation 1 as described in libkbfs/delayed_cancellation.go", "err", "=", "libcontext", ".", "EnableDelayedCancellationWithGracePeriod", "(", "ctx", ",", "d", ".", "folder", ".", "fs", ".", "config", ".", "DelayedCancellationGracePeriod", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "newNode", ",", "_", ",", "err", ":=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "CreateDir", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "child", ":=", "newDir", "(", "d", ".", "folder", ",", "newNode", ")", "\n", "d", ".", "folder", ".", "nodesMu", ".", "Lock", "(", ")", "\n", "d", ".", "folder", ".", "nodes", "[", "newNode", ".", "GetID", "(", ")", "]", "=", "child", "\n", "d", ".", "folder", ".", "nodesMu", ".", "Unlock", "(", ")", "\n", "return", "child", ",", "nil", "\n", "}" ]
// Mkdir implements the fs.NodeMkdirer interface for Dir.
[ "Mkdir", "implements", "the", "fs", ".", "NodeMkdirer", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L661-L688
161,339
keybase/client
go/kbfs/libfuse/dir.go
Symlink
func (d *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) ( node fs.Node, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Symlink", fmt.Sprintf("%s %s -> %s", d.node.GetBasename(), req.NewName, req.Target)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Dir Symlink %s -> %s", req.NewName, req.Target) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return nil, err } if _, err := d.folder.fs.config.KBFSOps().CreateLink( ctx, d.node, req.NewName, req.Target); err != nil { return nil, err } child := &Symlink{ parent: d, name: req.NewName, inode: d.folder.fs.assignInode(), } return child, nil }
go
func (d *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) ( node fs.Node, err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Symlink", fmt.Sprintf("%s %s -> %s", d.node.GetBasename(), req.NewName, req.Target)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Dir Symlink %s -> %s", req.NewName, req.Target) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return nil, err } if _, err := d.folder.fs.config.KBFSOps().CreateLink( ctx, d.node, req.NewName, req.Target); err != nil { return nil, err } child := &Symlink{ parent: d, name: req.NewName, inode: d.folder.fs.assignInode(), } return child, nil }
[ "func", "(", "d", "*", "Dir", ")", "Symlink", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "SymlinkRequest", ")", "(", "node", "fs", ".", "Node", ",", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "req", ".", "NewName", ",", "req", ".", "Target", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "req", ".", "NewName", ",", "req", ".", "Target", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "// This fits in situation 1 as described in libkbfs/delayed_cancellation.go", "err", "=", "libcontext", ".", "EnableDelayedCancellationWithGracePeriod", "(", "ctx", ",", "d", ".", "folder", ".", "fs", ".", "config", ".", "DelayedCancellationGracePeriod", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "CreateLink", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "NewName", ",", "req", ".", "Target", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "child", ":=", "&", "Symlink", "{", "parent", ":", "d", ",", "name", ":", "req", ".", "NewName", ",", "inode", ":", "d", ".", "folder", ".", "fs", ".", "assignInode", "(", ")", ",", "}", "\n", "return", "child", ",", "nil", "\n", "}" ]
// Symlink implements the fs.NodeSymlinker interface for Dir.
[ "Symlink", "implements", "the", "fs", ".", "NodeSymlinker", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L691-L720
161,340
keybase/client
go/kbfs/libfuse/dir.go
Rename
func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fs.Node) (err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Rename", fmt.Sprintf("%s %s -> %s", d.node.GetBasename(), req.OldName, req.NewName)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Dir Rename %s -> %s", req.OldName, req.NewName) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() var realNewDir *Dir switch newDir := newDir.(type) { case *Dir: realNewDir = newDir case *TLF: var err error realNewDir, err = newDir.loadDir(ctx) if err != nil { return err } case *FolderList, *Root: // This normally wouldn't happen since a presumably pre-check on // destination permissions would have failed. But in case it happens, it // should be a EACCES according to rename() man page. return fuse.Errno(syscall.EACCES) default: // This shouldn't happen unless we add other nodes. EIO is not in the error // codes listed in rename(), but there doesn't seem to be any suitable // error code listed for this situation either. return fuse.Errno(syscall.EIO) } err = d.folder.fs.config.KBFSOps().Rename(ctx, d.node, req.OldName, realNewDir.node, req.NewName) switch e := err.(type) { case nil: return nil case libkbfs.RenameAcrossDirsError: var execPathErr error e.ApplicationExecPath, execPathErr = sysutils.GetExecPathFromPID(req.Pid) if execPathErr != nil { d.folder.fs.log.CDebugf(ctx, "Dir Rename: getting exec path for PID %d error: %v", req.Pid, execPathErr) } return e default: return err } }
go
func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fs.Node) (err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Rename", fmt.Sprintf("%s %s -> %s", d.node.GetBasename(), req.OldName, req.NewName)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Dir Rename %s -> %s", req.OldName, req.NewName) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() var realNewDir *Dir switch newDir := newDir.(type) { case *Dir: realNewDir = newDir case *TLF: var err error realNewDir, err = newDir.loadDir(ctx) if err != nil { return err } case *FolderList, *Root: // This normally wouldn't happen since a presumably pre-check on // destination permissions would have failed. But in case it happens, it // should be a EACCES according to rename() man page. return fuse.Errno(syscall.EACCES) default: // This shouldn't happen unless we add other nodes. EIO is not in the error // codes listed in rename(), but there doesn't seem to be any suitable // error code listed for this situation either. return fuse.Errno(syscall.EIO) } err = d.folder.fs.config.KBFSOps().Rename(ctx, d.node, req.OldName, realNewDir.node, req.NewName) switch e := err.(type) { case nil: return nil case libkbfs.RenameAcrossDirsError: var execPathErr error e.ApplicationExecPath, execPathErr = sysutils.GetExecPathFromPID(req.Pid) if execPathErr != nil { d.folder.fs.log.CDebugf(ctx, "Dir Rename: getting exec path for PID %d error: %v", req.Pid, execPathErr) } return e default: return err } }
[ "func", "(", "d", "*", "Dir", ")", "Rename", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "RenameRequest", ",", "newDir", "fs", ".", "Node", ")", "(", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "req", ".", "OldName", ",", "req", ".", "NewName", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "req", ".", "OldName", ",", "req", ".", "NewName", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "var", "realNewDir", "*", "Dir", "\n", "switch", "newDir", ":=", "newDir", ".", "(", "type", ")", "{", "case", "*", "Dir", ":", "realNewDir", "=", "newDir", "\n", "case", "*", "TLF", ":", "var", "err", "error", "\n", "realNewDir", ",", "err", "=", "newDir", ".", "loadDir", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "*", "FolderList", ",", "*", "Root", ":", "// This normally wouldn't happen since a presumably pre-check on", "// destination permissions would have failed. But in case it happens, it", "// should be a EACCES according to rename() man page.", "return", "fuse", ".", "Errno", "(", "syscall", ".", "EACCES", ")", "\n", "default", ":", "// This shouldn't happen unless we add other nodes. EIO is not in the error", "// codes listed in rename(), but there doesn't seem to be any suitable", "// error code listed for this situation either.", "return", "fuse", ".", "Errno", "(", "syscall", ".", "EIO", ")", "\n", "}", "\n\n", "err", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "Rename", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "OldName", ",", "realNewDir", ".", "node", ",", "req", ".", "NewName", ")", "\n\n", "switch", "e", ":=", "err", ".", "(", "type", ")", "{", "case", "nil", ":", "return", "nil", "\n", "case", "libkbfs", ".", "RenameAcrossDirsError", ":", "var", "execPathErr", "error", "\n", "e", ".", "ApplicationExecPath", ",", "execPathErr", "=", "sysutils", ".", "GetExecPathFromPID", "(", "req", ".", "Pid", ")", "\n", "if", "execPathErr", "!=", "nil", "{", "d", ".", "folder", ".", "fs", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "req", ".", "Pid", ",", "execPathErr", ")", "\n", "}", "\n", "return", "e", "\n", "default", ":", "return", "err", "\n", "}", "\n", "}" ]
// Rename implements the fs.NodeRenamer interface for Dir.
[ "Rename", "implements", "the", "fs", ".", "NodeRenamer", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L723-L774
161,341
keybase/client
go/kbfs/libfuse/dir.go
Remove
func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Remove", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Remove %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } // node will be removed from Folder.nodes, if it is there in the // first place, by its Forget if req.Dir { err = d.folder.fs.config.KBFSOps().RemoveDir(ctx, d.node, req.Name) } else { err = d.folder.fs.config.KBFSOps().RemoveEntry(ctx, d.node, req.Name) } if err != nil { return err } return nil }
go
func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Remove", fmt.Sprintf("%s %s", d.node.GetBasename(), req.Name)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Remove %s", req.Name) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } // node will be removed from Folder.nodes, if it is there in the // first place, by its Forget if req.Dir { err = d.folder.fs.config.KBFSOps().RemoveDir(ctx, d.node, req.Name) } else { err = d.folder.fs.config.KBFSOps().RemoveEntry(ctx, d.node, req.Name) } if err != nil { return err } return nil }
[ "func", "(", "d", "*", "Dir", ")", "Remove", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "RemoveRequest", ")", "(", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "req", ".", "Name", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "req", ".", "Name", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "// This fits in situation 1 as described in libkbfs/delayed_cancellation.go", "err", "=", "libcontext", ".", "EnableDelayedCancellationWithGracePeriod", "(", "ctx", ",", "d", ".", "folder", ".", "fs", ".", "config", ".", "DelayedCancellationGracePeriod", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// node will be removed from Folder.nodes, if it is there in the", "// first place, by its Forget", "if", "req", ".", "Dir", "{", "err", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "RemoveDir", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "Name", ")", "\n", "}", "else", "{", "err", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "RemoveEntry", "(", "ctx", ",", "d", ".", "node", ",", "req", ".", "Name", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Remove implements the fs.NodeRemover interface for Dir.
[ "Remove", "implements", "the", "fs", ".", "NodeRemover", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L777-L805
161,342
keybase/client
go/kbfs/libfuse/dir.go
ReadDirAll
func (d *Dir) ReadDirAll(ctx context.Context) (res []fuse.Dirent, err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.ReadDirAll", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir ReadDirAll") defer func() { err = d.folder.processError(ctx, libkbfs.ReadMode, err) }() children, err := d.folder.fs.config.KBFSOps().GetDirChildren(ctx, d.node) if err != nil { return nil, err } for name, ei := range children { fde := fuse.Dirent{ Name: name, // Technically we should be setting the inode here, but // since we don't have a proper node for each of these // entries yet we can't generate one, because we don't // have anywhere to save it. So bazil.org/fuse will // generate a random one for each entry, but doesn't store // it anywhere, so it's safe. } switch ei.Type { case data.File, data.Exec: fde.Type = fuse.DT_File case data.Dir: fde.Type = fuse.DT_Dir case data.Sym: fde.Type = fuse.DT_Link } res = append(res, fde) } d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Returning %d entries", len(res)) return res, nil }
go
func (d *Dir) ReadDirAll(ctx context.Context) (res []fuse.Dirent, err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.ReadDirAll", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir ReadDirAll") defer func() { err = d.folder.processError(ctx, libkbfs.ReadMode, err) }() children, err := d.folder.fs.config.KBFSOps().GetDirChildren(ctx, d.node) if err != nil { return nil, err } for name, ei := range children { fde := fuse.Dirent{ Name: name, // Technically we should be setting the inode here, but // since we don't have a proper node for each of these // entries yet we can't generate one, because we don't // have anywhere to save it. So bazil.org/fuse will // generate a random one for each entry, but doesn't store // it anywhere, so it's safe. } switch ei.Type { case data.File, data.Exec: fde.Type = fuse.DT_File case data.Dir: fde.Type = fuse.DT_Dir case data.Sym: fde.Type = fuse.DT_Link } res = append(res, fde) } d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Returning %d entries", len(res)) return res, nil }
[ "func", "(", "d", "*", "Dir", ")", "ReadDirAll", "(", "ctx", "context", ".", "Context", ")", "(", "res", "[", "]", "fuse", ".", "Dirent", ",", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "ReadMode", ",", "err", ")", "}", "(", ")", "\n\n", "children", ",", "err", ":=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "GetDirChildren", "(", "ctx", ",", "d", ".", "node", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "name", ",", "ei", ":=", "range", "children", "{", "fde", ":=", "fuse", ".", "Dirent", "{", "Name", ":", "name", ",", "// Technically we should be setting the inode here, but", "// since we don't have a proper node for each of these", "// entries yet we can't generate one, because we don't", "// have anywhere to save it. So bazil.org/fuse will", "// generate a random one for each entry, but doesn't store", "// it anywhere, so it's safe.", "}", "\n", "switch", "ei", ".", "Type", "{", "case", "data", ".", "File", ",", "data", ".", "Exec", ":", "fde", ".", "Type", "=", "fuse", ".", "DT_File", "\n", "case", "data", ".", "Dir", ":", "fde", ".", "Type", "=", "fuse", ".", "DT_Dir", "\n", "case", "data", ".", "Sym", ":", "fde", ".", "Type", "=", "fuse", ".", "DT_Link", "\n", "}", "\n", "res", "=", "append", "(", "res", ",", "fde", ")", "\n", "}", "\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "len", "(", "res", ")", ")", "\n", "return", "res", ",", "nil", "\n", "}" ]
// ReadDirAll implements the fs.NodeReadDirAller interface for Dir.
[ "ReadDirAll", "implements", "the", "fs", ".", "NodeReadDirAller", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L808-L843
161,343
keybase/client
go/kbfs/libfuse/dir.go
Setattr
func (d *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) (err error) { valid := req.Valid ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Setattr", fmt.Sprintf("%s %s", d.node.GetBasename(), valid)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir SetAttr %s", valid) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() if valid.Mode() { // You can't set the mode on KBFS directories, but we don't // want to return EPERM because that unnecessarily fails some // applications like unzip. Instead ignore it, print a debug // message, and advertise this behavior on the // "understand_kbfs" doc online. d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Ignoring unsupported attempt to set "+ "the mode on a directory") valid &^= fuse.SetattrMode } if valid.Mtime() { err := d.folder.fs.config.KBFSOps().SetMtime( ctx, d.node, &req.Mtime) if err != nil { return err } valid &^= fuse.SetattrMtime | fuse.SetattrMtimeNow } // KBFS has no concept of persistent atime; explicitly don't handle it valid &^= fuse.SetattrAtime | fuse.SetattrAtimeNow // things we don't need to explicitly handle valid &^= fuse.SetattrLockOwner | fuse.SetattrHandle if valid.Uid() || valid.Gid() { // You can't set the UID/GID on KBFS directories, but we don't // want to return ENOSYS because that causes scary warnings on // some programs like mv. Instead ignore it, print a debug // message, and advertise this behavior on the // "understand_kbfs" doc online. d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Ignoring unsupported attempt to set "+ "the UID/GID on a directory") valid &^= fuse.SetattrUid | fuse.SetattrGid } if valid != 0 { // don't let an unhandled operation slip by without error d.folder.fs.log.CInfof(ctx, "Setattr did not handle %v", valid) return fuse.ENOSYS } // Something in Linux kernel *requires* directories to provide // attributes here, where it was just an optimization for files. return d.attr(ctx, &resp.Attr) }
go
func (d *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) (err error) { valid := req.Valid ctx = d.folder.fs.config.MaybeStartTrace(ctx, "Dir.Setattr", fmt.Sprintf("%s %s", d.node.GetBasename(), valid)) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir SetAttr %s", valid) defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() if valid.Mode() { // You can't set the mode on KBFS directories, but we don't // want to return EPERM because that unnecessarily fails some // applications like unzip. Instead ignore it, print a debug // message, and advertise this behavior on the // "understand_kbfs" doc online. d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Ignoring unsupported attempt to set "+ "the mode on a directory") valid &^= fuse.SetattrMode } if valid.Mtime() { err := d.folder.fs.config.KBFSOps().SetMtime( ctx, d.node, &req.Mtime) if err != nil { return err } valid &^= fuse.SetattrMtime | fuse.SetattrMtimeNow } // KBFS has no concept of persistent atime; explicitly don't handle it valid &^= fuse.SetattrAtime | fuse.SetattrAtimeNow // things we don't need to explicitly handle valid &^= fuse.SetattrLockOwner | fuse.SetattrHandle if valid.Uid() || valid.Gid() { // You can't set the UID/GID on KBFS directories, but we don't // want to return ENOSYS because that causes scary warnings on // some programs like mv. Instead ignore it, print a debug // message, and advertise this behavior on the // "understand_kbfs" doc online. d.folder.fs.vlog.CLogf( ctx, libkb.VLog1, "Ignoring unsupported attempt to set "+ "the UID/GID on a directory") valid &^= fuse.SetattrUid | fuse.SetattrGid } if valid != 0 { // don't let an unhandled operation slip by without error d.folder.fs.log.CInfof(ctx, "Setattr did not handle %v", valid) return fuse.ENOSYS } // Something in Linux kernel *requires* directories to provide // attributes here, where it was just an optimization for files. return d.attr(ctx, &resp.Attr) }
[ "func", "(", "d", "*", "Dir", ")", "Setattr", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "SetattrRequest", ",", "resp", "*", "fuse", ".", "SetattrResponse", ")", "(", "err", "error", ")", "{", "valid", ":=", "req", ".", "Valid", "\n", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ",", "valid", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ",", "valid", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "if", "valid", ".", "Mode", "(", ")", "{", "// You can't set the mode on KBFS directories, but we don't", "// want to return EPERM because that unnecessarily fails some", "// applications like unzip. Instead ignore it, print a debug", "// message, and advertise this behavior on the", "// \"understand_kbfs\" doc online.", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", "+", "\"", "\"", ")", "\n", "valid", "&^=", "fuse", ".", "SetattrMode", "\n", "}", "\n\n", "if", "valid", ".", "Mtime", "(", ")", "{", "err", ":=", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SetMtime", "(", "ctx", ",", "d", ".", "node", ",", "&", "req", ".", "Mtime", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "valid", "&^=", "fuse", ".", "SetattrMtime", "|", "fuse", ".", "SetattrMtimeNow", "\n", "}", "\n\n", "// KBFS has no concept of persistent atime; explicitly don't handle it", "valid", "&^=", "fuse", ".", "SetattrAtime", "|", "fuse", ".", "SetattrAtimeNow", "\n\n", "// things we don't need to explicitly handle", "valid", "&^=", "fuse", ".", "SetattrLockOwner", "|", "fuse", ".", "SetattrHandle", "\n\n", "if", "valid", ".", "Uid", "(", ")", "||", "valid", ".", "Gid", "(", ")", "{", "// You can't set the UID/GID on KBFS directories, but we don't", "// want to return ENOSYS because that causes scary warnings on", "// some programs like mv. Instead ignore it, print a debug", "// message, and advertise this behavior on the", "// \"understand_kbfs\" doc online.", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", "+", "\"", "\"", ")", "\n", "valid", "&^=", "fuse", ".", "SetattrUid", "|", "fuse", ".", "SetattrGid", "\n", "}", "\n\n", "if", "valid", "!=", "0", "{", "// don't let an unhandled operation slip by without error", "d", ".", "folder", ".", "fs", ".", "log", ".", "CInfof", "(", "ctx", ",", "\"", "\"", ",", "valid", ")", "\n", "return", "fuse", ".", "ENOSYS", "\n", "}", "\n\n", "// Something in Linux kernel *requires* directories to provide", "// attributes here, where it was just an optimization for files.", "return", "d", ".", "attr", "(", "ctx", ",", "&", "resp", ".", "Attr", ")", "\n", "}" ]
// Setattr implements the fs.NodeSetattrer interface for Dir.
[ "Setattr", "implements", "the", "fs", ".", "NodeSetattrer", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L851-L908
161,344
keybase/client
go/kbfs/libfuse/dir.go
Fsync
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Fsync", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Fsync") defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } return d.folder.fs.config.KBFSOps().SyncAll(ctx, d.node.GetFolderBranch()) }
go
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) { ctx = d.folder.fs.config.MaybeStartTrace( ctx, "Dir.Fsync", d.node.GetBasename()) defer func() { d.folder.fs.config.MaybeFinishTrace(ctx, err) }() d.folder.fs.vlog.CLogf(ctx, libkb.VLog1, "Dir Fsync") defer func() { err = d.folder.processError(ctx, libkbfs.WriteMode, err) }() // This fits in situation 1 as described in libkbfs/delayed_cancellation.go err = libcontext.EnableDelayedCancellationWithGracePeriod( ctx, d.folder.fs.config.DelayedCancellationGracePeriod()) if err != nil { return err } return d.folder.fs.config.KBFSOps().SyncAll(ctx, d.node.GetFolderBranch()) }
[ "func", "(", "d", "*", "Dir", ")", "Fsync", "(", "ctx", "context", ".", "Context", ",", "req", "*", "fuse", ".", "FsyncRequest", ")", "(", "err", "error", ")", "{", "ctx", "=", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeStartTrace", "(", "ctx", ",", "\"", "\"", ",", "d", ".", "node", ".", "GetBasename", "(", ")", ")", "\n", "defer", "func", "(", ")", "{", "d", ".", "folder", ".", "fs", ".", "config", ".", "MaybeFinishTrace", "(", "ctx", ",", "err", ")", "}", "(", ")", "\n\n", "d", ".", "folder", ".", "fs", ".", "vlog", ".", "CLogf", "(", "ctx", ",", "libkb", ".", "VLog1", ",", "\"", "\"", ")", "\n", "defer", "func", "(", ")", "{", "err", "=", "d", ".", "folder", ".", "processError", "(", "ctx", ",", "libkbfs", ".", "WriteMode", ",", "err", ")", "}", "(", ")", "\n\n", "// This fits in situation 1 as described in libkbfs/delayed_cancellation.go", "err", "=", "libcontext", ".", "EnableDelayedCancellationWithGracePeriod", "(", "ctx", ",", "d", ".", "folder", ".", "fs", ".", "config", ".", "DelayedCancellationGracePeriod", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "d", ".", "folder", ".", "fs", ".", "config", ".", "KBFSOps", "(", ")", ".", "SyncAll", "(", "ctx", ",", "d", ".", "node", ".", "GetFolderBranch", "(", ")", ")", "\n", "}" ]
// Fsync implements the fs.NodeFsyncer interface for Dir.
[ "Fsync", "implements", "the", "fs", ".", "NodeFsyncer", "interface", "for", "Dir", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/dir.go#L911-L927
161,345
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
cancelExistingLocked
func (cr *ConflictResolver) cancelExistingLocked(ci conflictInput) bool { // The input is only interesting if one of the revisions is // greater than what we've looked at to date. if ci.unmerged <= cr.currInput.unmerged && ci.merged <= cr.currInput.merged { return false } if cr.currCancel != nil { cr.currCancel() } return true }
go
func (cr *ConflictResolver) cancelExistingLocked(ci conflictInput) bool { // The input is only interesting if one of the revisions is // greater than what we've looked at to date. if ci.unmerged <= cr.currInput.unmerged && ci.merged <= cr.currInput.merged { return false } if cr.currCancel != nil { cr.currCancel() } return true }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "cancelExistingLocked", "(", "ci", "conflictInput", ")", "bool", "{", "// The input is only interesting if one of the revisions is", "// greater than what we've looked at to date.", "if", "ci", ".", "unmerged", "<=", "cr", ".", "currInput", ".", "unmerged", "&&", "ci", ".", "merged", "<=", "cr", ".", "currInput", ".", "merged", "{", "return", "false", "\n", "}", "\n", "if", "cr", ".", "currCancel", "!=", "nil", "{", "cr", ".", "currCancel", "(", ")", "\n", "}", "\n", "return", "true", "\n", "}" ]
// cancelExistingLocked must be called while holding cr.inputLock.
[ "cancelExistingLocked", "must", "be", "called", "while", "holding", "cr", ".", "inputLock", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L176-L187
161,346
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
ForceCancel
func (cr *ConflictResolver) ForceCancel() { cr.inputLock.Lock() defer cr.inputLock.Unlock() if cr.currCancel != nil { cr.currCancel() } }
go
func (cr *ConflictResolver) ForceCancel() { cr.inputLock.Lock() defer cr.inputLock.Unlock() if cr.currCancel != nil { cr.currCancel() } }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "ForceCancel", "(", ")", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "if", "cr", ".", "currCancel", "!=", "nil", "{", "cr", ".", "currCancel", "(", ")", "\n", "}", "\n", "}" ]
// ForceCancel cancels any currently-running CR, regardless of what // its inputs were.
[ "ForceCancel", "cancels", "any", "currently", "-", "running", "CR", "regardless", "of", "what", "its", "inputs", "were", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L191-L197
161,347
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
processInput
func (cr *ConflictResolver) processInput(baseCtx context.Context, inputChan <-chan conflictInput) { // Start off with a closed prevCRDone, so that the first CR call // doesn't have to wait. prevCRDone := make(chan struct{}) close(prevCRDone) defer func() { cr.inputLock.Lock() defer cr.inputLock.Unlock() if cr.currCancel != nil { cr.currCancel() } libcontext.CleanupCancellationDelayer(baseCtx) }() for ci := range inputChan { ctx := CtxWithRandomIDReplayable(baseCtx, CtxCRIDKey, CtxCROpID, cr.log) valid := func() bool { cr.inputLock.Lock() defer cr.inputLock.Unlock() valid := cr.cancelExistingLocked(ci) if !valid { return false } cr.log.CDebugf(ctx, "New conflict input %v following old "+ "input %v", ci, cr.currInput) cr.currInput = ci ctx, cr.currCancel = context.WithCancel(ctx) return true }() if !valid { cr.log.CDebugf(ctx, "Ignoring uninteresting input: %v", ci) cr.resolveGroup.Done() continue } waitChan := prevCRDone prevCRDone = make(chan struct{}) // closed when doResolve finishes go func(ci conflictInput, done chan<- struct{}) { defer cr.resolveGroup.Done() defer close(done) // Wait for the previous CR without blocking any // Resolve callers, as that could result in deadlock // (KBFS-1001). select { case <-waitChan: case <-ctx.Done(): cr.log.CDebugf(ctx, "Resolution canceled before starting") return } cr.doResolve(ctx, ci) }(ci, prevCRDone) } }
go
func (cr *ConflictResolver) processInput(baseCtx context.Context, inputChan <-chan conflictInput) { // Start off with a closed prevCRDone, so that the first CR call // doesn't have to wait. prevCRDone := make(chan struct{}) close(prevCRDone) defer func() { cr.inputLock.Lock() defer cr.inputLock.Unlock() if cr.currCancel != nil { cr.currCancel() } libcontext.CleanupCancellationDelayer(baseCtx) }() for ci := range inputChan { ctx := CtxWithRandomIDReplayable(baseCtx, CtxCRIDKey, CtxCROpID, cr.log) valid := func() bool { cr.inputLock.Lock() defer cr.inputLock.Unlock() valid := cr.cancelExistingLocked(ci) if !valid { return false } cr.log.CDebugf(ctx, "New conflict input %v following old "+ "input %v", ci, cr.currInput) cr.currInput = ci ctx, cr.currCancel = context.WithCancel(ctx) return true }() if !valid { cr.log.CDebugf(ctx, "Ignoring uninteresting input: %v", ci) cr.resolveGroup.Done() continue } waitChan := prevCRDone prevCRDone = make(chan struct{}) // closed when doResolve finishes go func(ci conflictInput, done chan<- struct{}) { defer cr.resolveGroup.Done() defer close(done) // Wait for the previous CR without blocking any // Resolve callers, as that could result in deadlock // (KBFS-1001). select { case <-waitChan: case <-ctx.Done(): cr.log.CDebugf(ctx, "Resolution canceled before starting") return } cr.doResolve(ctx, ci) }(ci, prevCRDone) } }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "processInput", "(", "baseCtx", "context", ".", "Context", ",", "inputChan", "<-", "chan", "conflictInput", ")", "{", "// Start off with a closed prevCRDone, so that the first CR call", "// doesn't have to wait.", "prevCRDone", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "close", "(", "prevCRDone", ")", "\n", "defer", "func", "(", ")", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "if", "cr", ".", "currCancel", "!=", "nil", "{", "cr", ".", "currCancel", "(", ")", "\n", "}", "\n", "libcontext", ".", "CleanupCancellationDelayer", "(", "baseCtx", ")", "\n", "}", "(", ")", "\n", "for", "ci", ":=", "range", "inputChan", "{", "ctx", ":=", "CtxWithRandomIDReplayable", "(", "baseCtx", ",", "CtxCRIDKey", ",", "CtxCROpID", ",", "cr", ".", "log", ")", "\n\n", "valid", ":=", "func", "(", ")", "bool", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "valid", ":=", "cr", ".", "cancelExistingLocked", "(", "ci", ")", "\n", "if", "!", "valid", "{", "return", "false", "\n", "}", "\n", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", "+", "\"", "\"", ",", "ci", ",", "cr", ".", "currInput", ")", "\n", "cr", ".", "currInput", "=", "ci", "\n", "ctx", ",", "cr", ".", "currCancel", "=", "context", ".", "WithCancel", "(", "ctx", ")", "\n", "return", "true", "\n", "}", "(", ")", "\n", "if", "!", "valid", "{", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "ci", ")", "\n", "cr", ".", "resolveGroup", ".", "Done", "(", ")", "\n", "continue", "\n", "}", "\n\n", "waitChan", ":=", "prevCRDone", "\n", "prevCRDone", "=", "make", "(", "chan", "struct", "{", "}", ")", "// closed when doResolve finishes", "\n", "go", "func", "(", "ci", "conflictInput", ",", "done", "chan", "<-", "struct", "{", "}", ")", "{", "defer", "cr", ".", "resolveGroup", ".", "Done", "(", ")", "\n", "defer", "close", "(", "done", ")", "\n", "// Wait for the previous CR without blocking any", "// Resolve callers, as that could result in deadlock", "// (KBFS-1001).", "select", "{", "case", "<-", "waitChan", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "cr", ".", "doResolve", "(", "ctx", ",", "ci", ")", "\n", "}", "(", "ci", ",", "prevCRDone", ")", "\n", "}", "\n", "}" ]
// processInput processes conflict resolution jobs from the given // channel until it is closed. This function uses a parameter for the // channel instead of accessing cr.inputChan directly so that it // doesn't have to hold inputChanLock.
[ "processInput", "processes", "conflict", "resolution", "jobs", "from", "the", "given", "channel", "until", "it", "is", "closed", ".", "This", "function", "uses", "a", "parameter", "for", "the", "channel", "instead", "of", "accessing", "cr", ".", "inputChan", "directly", "so", "that", "it", "doesn", "t", "have", "to", "hold", "inputChanLock", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L203-L257
161,348
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
Resolve
func (cr *ConflictResolver) Resolve(ctx context.Context, unmerged kbfsmd.Revision, merged kbfsmd.Revision) { cr.inputChanLock.RLock() defer cr.inputChanLock.RUnlock() // CR can end up trying to cancel itself via the SyncAll call, so // prevent that from happening. if crOpID := ctx.Value(CtxCRIDKey); crOpID != nil { cr.log.CDebugf(ctx, "Ignoring self-resolve during CR") return } if cr.inputChan == nil { return } // Call Add before cancelling existing CR in order to prevent the // resolveGroup from becoming briefly empty and allowing things waiting // on it to believe that CR has finished. cr.resolveGroup.Add(1) ci := conflictInput{unmerged, merged} func() { cr.inputLock.Lock() defer cr.inputLock.Unlock() // Cancel any running CR before we return, so the caller can be // confident any ongoing CR superseded by this new input will be // canceled before it releases any locks it holds. // // TODO: return early if this returns false, and log something // using a newly-pass-in context. _ = cr.cancelExistingLocked(ci) }() cr.inputChan <- ci }
go
func (cr *ConflictResolver) Resolve(ctx context.Context, unmerged kbfsmd.Revision, merged kbfsmd.Revision) { cr.inputChanLock.RLock() defer cr.inputChanLock.RUnlock() // CR can end up trying to cancel itself via the SyncAll call, so // prevent that from happening. if crOpID := ctx.Value(CtxCRIDKey); crOpID != nil { cr.log.CDebugf(ctx, "Ignoring self-resolve during CR") return } if cr.inputChan == nil { return } // Call Add before cancelling existing CR in order to prevent the // resolveGroup from becoming briefly empty and allowing things waiting // on it to believe that CR has finished. cr.resolveGroup.Add(1) ci := conflictInput{unmerged, merged} func() { cr.inputLock.Lock() defer cr.inputLock.Unlock() // Cancel any running CR before we return, so the caller can be // confident any ongoing CR superseded by this new input will be // canceled before it releases any locks it holds. // // TODO: return early if this returns false, and log something // using a newly-pass-in context. _ = cr.cancelExistingLocked(ci) }() cr.inputChan <- ci }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "Resolve", "(", "ctx", "context", ".", "Context", ",", "unmerged", "kbfsmd", ".", "Revision", ",", "merged", "kbfsmd", ".", "Revision", ")", "{", "cr", ".", "inputChanLock", ".", "RLock", "(", ")", "\n", "defer", "cr", ".", "inputChanLock", ".", "RUnlock", "(", ")", "\n\n", "// CR can end up trying to cancel itself via the SyncAll call, so", "// prevent that from happening.", "if", "crOpID", ":=", "ctx", ".", "Value", "(", "CtxCRIDKey", ")", ";", "crOpID", "!=", "nil", "{", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "if", "cr", ".", "inputChan", "==", "nil", "{", "return", "\n", "}", "\n\n", "// Call Add before cancelling existing CR in order to prevent the", "// resolveGroup from becoming briefly empty and allowing things waiting", "// on it to believe that CR has finished.", "cr", ".", "resolveGroup", ".", "Add", "(", "1", ")", "\n\n", "ci", ":=", "conflictInput", "{", "unmerged", ",", "merged", "}", "\n", "func", "(", ")", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "// Cancel any running CR before we return, so the caller can be", "// confident any ongoing CR superseded by this new input will be", "// canceled before it releases any locks it holds.", "//", "// TODO: return early if this returns false, and log something", "// using a newly-pass-in context.", "_", "=", "cr", ".", "cancelExistingLocked", "(", "ci", ")", "\n", "}", "(", ")", "\n\n", "cr", ".", "inputChan", "<-", "ci", "\n", "}" ]
// Resolve takes the latest known unmerged and merged revision // numbers, and kicks off the resolution process.
[ "Resolve", "takes", "the", "latest", "known", "unmerged", "and", "merged", "revision", "numbers", "and", "kicks", "off", "the", "resolution", "process", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L261-L296
161,349
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
BeginNewBranch
func (cr *ConflictResolver) BeginNewBranch() { cr.inputLock.Lock() defer cr.inputLock.Unlock() // Reset the curr input so we don't ignore a future CR // request that uses the same revision number (i.e., // because the previous CR failed to flush due to a // conflict). cr.currInput = conflictInput{} }
go
func (cr *ConflictResolver) BeginNewBranch() { cr.inputLock.Lock() defer cr.inputLock.Unlock() // Reset the curr input so we don't ignore a future CR // request that uses the same revision number (i.e., // because the previous CR failed to flush due to a // conflict). cr.currInput = conflictInput{} }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "BeginNewBranch", "(", ")", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "// Reset the curr input so we don't ignore a future CR", "// request that uses the same revision number (i.e.,", "// because the previous CR failed to flush due to a", "// conflict).", "cr", ".", "currInput", "=", "conflictInput", "{", "}", "\n", "}" ]
// BeginNewBranch resets any internal state to be ready to accept // resolutions from a new branch.
[ "BeginNewBranch", "resets", "any", "internal", "state", "to", "be", "ready", "to", "accept", "resolutions", "from", "a", "new", "branch", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L325-L333
161,350
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
updateCurrInput
func (cr *ConflictResolver) updateCurrInput(ctx context.Context, unmerged, merged []ImmutableRootMetadata) (err error) { cr.inputLock.Lock() defer cr.inputLock.Unlock() // check done while holding the lock, so we know for sure if // we've already been canceled and replaced by a new input. err = cr.checkDone(ctx) if err != nil { return err } prevInput := cr.currInput defer func() { // reset the currInput if we get an error below if err != nil { cr.currInput = prevInput } }() rev := unmerged[len(unmerged)-1].bareMd.RevisionNumber() if rev < cr.currInput.unmerged { return fmt.Errorf("Unmerged revision %d is lower than the "+ "expected unmerged revision %d", rev, cr.currInput.unmerged) } cr.currInput.unmerged = rev if len(merged) > 0 { rev = merged[len(merged)-1].bareMd.RevisionNumber() if rev < cr.currInput.merged { return fmt.Errorf("Merged revision %d is lower than the "+ "expected merged revision %d", rev, cr.currInput.merged) } } else { rev = kbfsmd.RevisionUninitialized } cr.currInput.merged = rev // Take the lock right away next time if either there are lots of // unmerged revisions, or this is a local squash and we won't // block for very long. // // TODO: if there are a lot of merged revisions, and they keep // coming, we might consider doing a "partial" resolution, writing // the result back to the unmerged branch (basically "rebasing" // it). See KBFS-1896. if (len(unmerged) > cr.maxRevsThreshold) || (len(unmerged) > 0 && unmerged[0].BID() == kbfsmd.PendingLocalSquashBranchID) { cr.lockNextTime = true } return nil }
go
func (cr *ConflictResolver) updateCurrInput(ctx context.Context, unmerged, merged []ImmutableRootMetadata) (err error) { cr.inputLock.Lock() defer cr.inputLock.Unlock() // check done while holding the lock, so we know for sure if // we've already been canceled and replaced by a new input. err = cr.checkDone(ctx) if err != nil { return err } prevInput := cr.currInput defer func() { // reset the currInput if we get an error below if err != nil { cr.currInput = prevInput } }() rev := unmerged[len(unmerged)-1].bareMd.RevisionNumber() if rev < cr.currInput.unmerged { return fmt.Errorf("Unmerged revision %d is lower than the "+ "expected unmerged revision %d", rev, cr.currInput.unmerged) } cr.currInput.unmerged = rev if len(merged) > 0 { rev = merged[len(merged)-1].bareMd.RevisionNumber() if rev < cr.currInput.merged { return fmt.Errorf("Merged revision %d is lower than the "+ "expected merged revision %d", rev, cr.currInput.merged) } } else { rev = kbfsmd.RevisionUninitialized } cr.currInput.merged = rev // Take the lock right away next time if either there are lots of // unmerged revisions, or this is a local squash and we won't // block for very long. // // TODO: if there are a lot of merged revisions, and they keep // coming, we might consider doing a "partial" resolution, writing // the result back to the unmerged branch (basically "rebasing" // it). See KBFS-1896. if (len(unmerged) > cr.maxRevsThreshold) || (len(unmerged) > 0 && unmerged[0].BID() == kbfsmd.PendingLocalSquashBranchID) { cr.lockNextTime = true } return nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "updateCurrInput", "(", "ctx", "context", ".", "Context", ",", "unmerged", ",", "merged", "[", "]", "ImmutableRootMetadata", ")", "(", "err", "error", ")", "{", "cr", ".", "inputLock", ".", "Lock", "(", ")", "\n", "defer", "cr", ".", "inputLock", ".", "Unlock", "(", ")", "\n", "// check done while holding the lock, so we know for sure if", "// we've already been canceled and replaced by a new input.", "err", "=", "cr", ".", "checkDone", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "prevInput", ":=", "cr", ".", "currInput", "\n", "defer", "func", "(", ")", "{", "// reset the currInput if we get an error below", "if", "err", "!=", "nil", "{", "cr", ".", "currInput", "=", "prevInput", "\n", "}", "\n", "}", "(", ")", "\n\n", "rev", ":=", "unmerged", "[", "len", "(", "unmerged", ")", "-", "1", "]", ".", "bareMd", ".", "RevisionNumber", "(", ")", "\n", "if", "rev", "<", "cr", ".", "currInput", ".", "unmerged", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "rev", ",", "cr", ".", "currInput", ".", "unmerged", ")", "\n", "}", "\n", "cr", ".", "currInput", ".", "unmerged", "=", "rev", "\n\n", "if", "len", "(", "merged", ")", ">", "0", "{", "rev", "=", "merged", "[", "len", "(", "merged", ")", "-", "1", "]", ".", "bareMd", ".", "RevisionNumber", "(", ")", "\n", "if", "rev", "<", "cr", ".", "currInput", ".", "merged", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "rev", ",", "cr", ".", "currInput", ".", "merged", ")", "\n", "}", "\n", "}", "else", "{", "rev", "=", "kbfsmd", ".", "RevisionUninitialized", "\n", "}", "\n", "cr", ".", "currInput", ".", "merged", "=", "rev", "\n\n", "// Take the lock right away next time if either there are lots of", "// unmerged revisions, or this is a local squash and we won't", "// block for very long.", "//", "// TODO: if there are a lot of merged revisions, and they keep", "// coming, we might consider doing a \"partial\" resolution, writing", "// the result back to the unmerged branch (basically \"rebasing\"", "// it). See KBFS-1896.", "if", "(", "len", "(", "unmerged", ")", ">", "cr", ".", "maxRevsThreshold", ")", "||", "(", "len", "(", "unmerged", ")", ">", "0", "&&", "unmerged", "[", "0", "]", ".", "BID", "(", ")", "==", "kbfsmd", ".", "PendingLocalSquashBranchID", ")", "{", "cr", ".", "lockNextTime", "=", "true", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// updateCurrInput assumes that both unmerged and merged are // non-empty.
[ "updateCurrInput", "assumes", "that", "both", "unmerged", "and", "merged", "are", "non", "-", "empty", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L413-L463
161,351
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
Less
func (sp crSortedPaths) Less(i, j int) bool { return len(sp[i].Path) > len(sp[j].Path) }
go
func (sp crSortedPaths) Less(i, j int) bool { return len(sp[i].Path) > len(sp[j].Path) }
[ "func", "(", "sp", "crSortedPaths", ")", "Less", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "len", "(", "sp", "[", "i", "]", ".", "Path", ")", ">", "len", "(", "sp", "[", "j", "]", ".", "Path", ")", "\n", "}" ]
// Less implements sort.Interface for crSortedPaths
[ "Less", "implements", "sort", ".", "Interface", "for", "crSortedPaths" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L523-L525
161,352
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
Swap
func (sp crSortedPaths) Swap(i, j int) { sp[j], sp[i] = sp[i], sp[j] }
go
func (sp crSortedPaths) Swap(i, j int) { sp[j], sp[i] = sp[i], sp[j] }
[ "func", "(", "sp", "crSortedPaths", ")", "Swap", "(", "i", ",", "j", "int", ")", "{", "sp", "[", "j", "]", ",", "sp", "[", "i", "]", "=", "sp", "[", "i", "]", ",", "sp", "[", "j", "]", "\n", "}" ]
// Swap implements sort.Interface for crSortedPaths
[ "Swap", "implements", "sort", ".", "Interface", "for", "crSortedPaths" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L528-L530
161,353
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
createdFileWithNonzeroSizes
func (cr *ConflictResolver) createdFileWithNonzeroSizes( ctx context.Context, unmergedChains, mergedChains *crChains, unmergedChain *crChain, mergedChain *crChain, unmergedCop, mergedCop *createOp) (bool, error) { lState := makeFBOLockState() // The pointers on the ops' final paths aren't necessarily filled // in, so construct our own partial paths using the chain // pointers, which are enough to satisfy `GetEntry`. mergedPath := data.Path{ FolderBranch: mergedCop.getFinalPath().FolderBranch, Path: []data.PathNode{ {BlockPointer: mergedChain.mostRecent, Name: ""}, {BlockPointer: data.ZeroPtr, Name: mergedCop.NewName}, }, } kmd := mergedChains.mostRecentChainMDInfo mergedEntry, err := cr.fbo.blocks.GetEntry(ctx, lState, kmd, mergedPath) if _, noExists := errors.Cause(err).(idutil.NoSuchNameError); noExists { return false, nil } else if err != nil { return false, err } kmd = unmergedChains.mostRecentChainMDInfo unmergedPath := data.Path{ FolderBranch: mergedCop.getFinalPath().FolderBranch, Path: []data.PathNode{ {BlockPointer: unmergedChain.mostRecent, Name: ""}, {BlockPointer: data.ZeroPtr, Name: mergedCop.NewName}, }, } unmergedEntry, err := cr.fbo.blocks.GetEntry(ctx, lState, kmd, unmergedPath) if _, noExists := errors.Cause(err).(idutil.NoSuchNameError); noExists { return false, nil } else if err != nil { return false, err } if mergedEntry.Size > 0 && unmergedEntry.Size > 0 { cr.log.CDebugf(ctx, "Not merging files named %s with non-zero sizes "+ "(merged=%d unmerged=%d)", unmergedCop.NewName, mergedEntry.Size, unmergedEntry.Size) return true, nil } return false, nil }
go
func (cr *ConflictResolver) createdFileWithNonzeroSizes( ctx context.Context, unmergedChains, mergedChains *crChains, unmergedChain *crChain, mergedChain *crChain, unmergedCop, mergedCop *createOp) (bool, error) { lState := makeFBOLockState() // The pointers on the ops' final paths aren't necessarily filled // in, so construct our own partial paths using the chain // pointers, which are enough to satisfy `GetEntry`. mergedPath := data.Path{ FolderBranch: mergedCop.getFinalPath().FolderBranch, Path: []data.PathNode{ {BlockPointer: mergedChain.mostRecent, Name: ""}, {BlockPointer: data.ZeroPtr, Name: mergedCop.NewName}, }, } kmd := mergedChains.mostRecentChainMDInfo mergedEntry, err := cr.fbo.blocks.GetEntry(ctx, lState, kmd, mergedPath) if _, noExists := errors.Cause(err).(idutil.NoSuchNameError); noExists { return false, nil } else if err != nil { return false, err } kmd = unmergedChains.mostRecentChainMDInfo unmergedPath := data.Path{ FolderBranch: mergedCop.getFinalPath().FolderBranch, Path: []data.PathNode{ {BlockPointer: unmergedChain.mostRecent, Name: ""}, {BlockPointer: data.ZeroPtr, Name: mergedCop.NewName}, }, } unmergedEntry, err := cr.fbo.blocks.GetEntry(ctx, lState, kmd, unmergedPath) if _, noExists := errors.Cause(err).(idutil.NoSuchNameError); noExists { return false, nil } else if err != nil { return false, err } if mergedEntry.Size > 0 && unmergedEntry.Size > 0 { cr.log.CDebugf(ctx, "Not merging files named %s with non-zero sizes "+ "(merged=%d unmerged=%d)", unmergedCop.NewName, mergedEntry.Size, unmergedEntry.Size) return true, nil } return false, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "createdFileWithNonzeroSizes", "(", "ctx", "context", ".", "Context", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "unmergedChain", "*", "crChain", ",", "mergedChain", "*", "crChain", ",", "unmergedCop", ",", "mergedCop", "*", "createOp", ")", "(", "bool", ",", "error", ")", "{", "lState", ":=", "makeFBOLockState", "(", ")", "\n", "// The pointers on the ops' final paths aren't necessarily filled", "// in, so construct our own partial paths using the chain", "// pointers, which are enough to satisfy `GetEntry`.", "mergedPath", ":=", "data", ".", "Path", "{", "FolderBranch", ":", "mergedCop", ".", "getFinalPath", "(", ")", ".", "FolderBranch", ",", "Path", ":", "[", "]", "data", ".", "PathNode", "{", "{", "BlockPointer", ":", "mergedChain", ".", "mostRecent", ",", "Name", ":", "\"", "\"", "}", ",", "{", "BlockPointer", ":", "data", ".", "ZeroPtr", ",", "Name", ":", "mergedCop", ".", "NewName", "}", ",", "}", ",", "}", "\n", "kmd", ":=", "mergedChains", ".", "mostRecentChainMDInfo", "\n", "mergedEntry", ",", "err", ":=", "cr", ".", "fbo", ".", "blocks", ".", "GetEntry", "(", "ctx", ",", "lState", ",", "kmd", ",", "mergedPath", ")", "\n", "if", "_", ",", "noExists", ":=", "errors", ".", "Cause", "(", "err", ")", ".", "(", "idutil", ".", "NoSuchNameError", ")", ";", "noExists", "{", "return", "false", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "kmd", "=", "unmergedChains", ".", "mostRecentChainMDInfo", "\n", "unmergedPath", ":=", "data", ".", "Path", "{", "FolderBranch", ":", "mergedCop", ".", "getFinalPath", "(", ")", ".", "FolderBranch", ",", "Path", ":", "[", "]", "data", ".", "PathNode", "{", "{", "BlockPointer", ":", "unmergedChain", ".", "mostRecent", ",", "Name", ":", "\"", "\"", "}", ",", "{", "BlockPointer", ":", "data", ".", "ZeroPtr", ",", "Name", ":", "mergedCop", ".", "NewName", "}", ",", "}", ",", "}", "\n", "unmergedEntry", ",", "err", ":=", "cr", ".", "fbo", ".", "blocks", ".", "GetEntry", "(", "ctx", ",", "lState", ",", "kmd", ",", "unmergedPath", ")", "\n", "if", "_", ",", "noExists", ":=", "errors", ".", "Cause", "(", "err", ")", ".", "(", "idutil", ".", "NoSuchNameError", ")", ";", "noExists", "{", "return", "false", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "mergedEntry", ".", "Size", ">", "0", "&&", "unmergedEntry", ".", "Size", ">", "0", "{", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", "+", "\"", "\"", ",", "unmergedCop", ".", "NewName", ",", "mergedEntry", ".", "Size", ",", "unmergedEntry", ".", "Size", ")", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// createdFileWithNonzeroSizes checks two possibly-conflicting // createOps and returns true if the corresponding file has non-zero // directory entry sizes in both the unmerged and merged branch. We // need to check this sometimes, because a call to // `createdFileWithConflictingWrite` might not have access to syncOps // that have been resolved away in a previous iteration. See // KBFS-2825 for details.
[ "createdFileWithNonzeroSizes", "checks", "two", "possibly", "-", "conflicting", "createOps", "and", "returns", "true", "if", "the", "corresponding", "file", "has", "non", "-", "zero", "directory", "entry", "sizes", "in", "both", "the", "unmerged", "and", "merged", "branch", ".", "We", "need", "to", "check", "this", "sometimes", "because", "a", "call", "to", "createdFileWithConflictingWrite", "might", "not", "have", "access", "to", "syncOps", "that", "have", "been", "resolved", "away", "in", "a", "previous", "iteration", ".", "See", "KBFS", "-", "2825", "for", "details", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L574-L620
161,354
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
findCreatedDirsToMerge
func (cr *ConflictResolver) findCreatedDirsToMerge(ctx context.Context, unmergedPaths []data.Path, unmergedChains, mergedChains *crChains) ( []data.Path, error) { var newUnmergedPaths []data.Path for _, unmergedPath := range unmergedPaths { unmergedChain, ok := unmergedChains.byMostRecent[unmergedPath.TailPointer()] if !ok { return nil, fmt.Errorf("findCreatedDirsToMerge: No unmerged chain "+ "for most recent %v", unmergedPath.TailPointer()) } newPaths, err := cr.checkPathForMerge(ctx, unmergedChain, unmergedPath, unmergedChains, mergedChains) if err != nil { return nil, err } newUnmergedPaths = append(newUnmergedPaths, newPaths...) } return newUnmergedPaths, nil }
go
func (cr *ConflictResolver) findCreatedDirsToMerge(ctx context.Context, unmergedPaths []data.Path, unmergedChains, mergedChains *crChains) ( []data.Path, error) { var newUnmergedPaths []data.Path for _, unmergedPath := range unmergedPaths { unmergedChain, ok := unmergedChains.byMostRecent[unmergedPath.TailPointer()] if !ok { return nil, fmt.Errorf("findCreatedDirsToMerge: No unmerged chain "+ "for most recent %v", unmergedPath.TailPointer()) } newPaths, err := cr.checkPathForMerge(ctx, unmergedChain, unmergedPath, unmergedChains, mergedChains) if err != nil { return nil, err } newUnmergedPaths = append(newUnmergedPaths, newPaths...) } return newUnmergedPaths, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "findCreatedDirsToMerge", "(", "ctx", "context", ".", "Context", ",", "unmergedPaths", "[", "]", "data", ".", "Path", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ")", "(", "[", "]", "data", ".", "Path", ",", "error", ")", "{", "var", "newUnmergedPaths", "[", "]", "data", ".", "Path", "\n", "for", "_", ",", "unmergedPath", ":=", "range", "unmergedPaths", "{", "unmergedChain", ",", "ok", ":=", "unmergedChains", ".", "byMostRecent", "[", "unmergedPath", ".", "TailPointer", "(", ")", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "unmergedPath", ".", "TailPointer", "(", ")", ")", "\n", "}", "\n\n", "newPaths", ",", "err", ":=", "cr", ".", "checkPathForMerge", "(", "ctx", ",", "unmergedChain", ",", "unmergedPath", ",", "unmergedChains", ",", "mergedChains", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "newUnmergedPaths", "=", "append", "(", "newUnmergedPaths", ",", "newPaths", "...", ")", "\n", "}", "\n", "return", "newUnmergedPaths", ",", "nil", "\n", "}" ]
// findCreatedDirsToMerge finds directories that were created in both // the unmerged and merged branches, and resets the original unmerged // pointer to match the original merged pointer. It returns a slice of // new unmerged paths that need to be combined with the unmergedPaths // slice.
[ "findCreatedDirsToMerge", "finds", "directories", "that", "were", "created", "in", "both", "the", "unmerged", "and", "merged", "branches", "and", "resets", "the", "original", "unmerged", "pointer", "to", "match", "the", "original", "merged", "pointer", ".", "It", "returns", "a", "slice", "of", "new", "unmerged", "paths", "that", "need", "to", "be", "combined", "with", "the", "unmergedPaths", "slice", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L768-L788
161,355
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
addChildBlocksIfIndirectFile
func (cr *ConflictResolver) addChildBlocksIfIndirectFile( ctx context.Context, lState *kbfssync.LockState, unmergedChains *crChains, currPath data.Path, op op) error { // For files with indirect pointers, add all child blocks // as refblocks for the re-created file. infos, err := cr.fbo.blocks.GetIndirectFileBlockInfos( ctx, lState, unmergedChains.mostRecentChainMDInfo, currPath) if err != nil { return err } if len(infos) > 0 { cr.log.CDebugf(ctx, "Adding child pointers for recreated "+ "file %s", currPath) for _, info := range infos { op.AddRefBlock(info.BlockPointer) } } return nil }
go
func (cr *ConflictResolver) addChildBlocksIfIndirectFile( ctx context.Context, lState *kbfssync.LockState, unmergedChains *crChains, currPath data.Path, op op) error { // For files with indirect pointers, add all child blocks // as refblocks for the re-created file. infos, err := cr.fbo.blocks.GetIndirectFileBlockInfos( ctx, lState, unmergedChains.mostRecentChainMDInfo, currPath) if err != nil { return err } if len(infos) > 0 { cr.log.CDebugf(ctx, "Adding child pointers for recreated "+ "file %s", currPath) for _, info := range infos { op.AddRefBlock(info.BlockPointer) } } return nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "addChildBlocksIfIndirectFile", "(", "ctx", "context", ".", "Context", ",", "lState", "*", "kbfssync", ".", "LockState", ",", "unmergedChains", "*", "crChains", ",", "currPath", "data", ".", "Path", ",", "op", "op", ")", "error", "{", "// For files with indirect pointers, add all child blocks", "// as refblocks for the re-created file.", "infos", ",", "err", ":=", "cr", ".", "fbo", ".", "blocks", ".", "GetIndirectFileBlockInfos", "(", "ctx", ",", "lState", ",", "unmergedChains", ".", "mostRecentChainMDInfo", ",", "currPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "infos", ")", ">", "0", "{", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", "+", "\"", "\"", ",", "currPath", ")", "\n", "for", "_", ",", "info", ":=", "range", "infos", "{", "op", ".", "AddRefBlock", "(", "info", ".", "BlockPointer", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// addChildBlocksIfIndirectFile adds refblocks for all child blocks of // the given file. It will return an error if called with a pointer // that doesn't represent a file.
[ "addChildBlocksIfIndirectFile", "adds", "refblocks", "for", "all", "child", "blocks", "of", "the", "given", "file", ".", "It", "will", "return", "an", "error", "if", "called", "with", "a", "pointer", "that", "doesn", "t", "represent", "a", "file", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L798-L816
161,356
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
addRecreateOpsToUnmergedChains
func (cr *ConflictResolver) addRecreateOpsToUnmergedChains(ctx context.Context, recreateOps []*createOp, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) ([]data.Path, error) { if len(recreateOps) == 0 { return nil, nil } // First create a lookup table that maps every block pointer in // every merged path to a corresponding key in the mergedPaths map. keys := make(map[data.BlockPointer]data.BlockPointer) for ptr, p := range mergedPaths { for _, node := range p.Path { keys[node.BlockPointer] = ptr } } var newUnmergedPaths []data.Path for _, rop := range recreateOps { // If rop.Dir.Unref is a merged most recent pointer, look up the // original. Otherwise rop.Dir.Unref is the original. Use the // original to look up the appropriate unmerged chain and stick // this op at the front. origTargetPtr, err := mergedChains.originalFromMostRecentOrSame(rop.Dir.Unref) if err != nil { return nil, err } chain, ok := unmergedChains.byOriginal[origTargetPtr] if !ok { return nil, fmt.Errorf("recreateOp for %v has no chain", origTargetPtr) } if len(chain.ops) == 0 { newUnmergedPaths = append(newUnmergedPaths, rop.getFinalPath()) } chain.ops = append([]op{rop}, chain.ops...) // Look up the corresponding unmerged most recent pointer, and // check whether there's a merged path for it yet. If not, // create one by looking it up in the lookup table (created // above) and taking the appropriate subpath. _, ok = mergedPaths[chain.mostRecent] if !ok { mergedMostRecent := chain.original if !mergedChains.isDeleted(chain.original) { if mChain, ok := mergedChains.byOriginal[chain.original]; ok { mergedMostRecent = mChain.mostRecent } } key, ok := keys[mergedMostRecent] if !ok { return nil, fmt.Errorf("Couldn't find a merged path "+ "containing the target of a recreate op: %v", mergedMostRecent) } currPath := mergedPaths[key] for currPath.TailPointer() != mergedMostRecent && currPath.HasValidParent() { currPath = *currPath.ParentPath() } mergedPaths[chain.mostRecent] = currPath } } return newUnmergedPaths, nil }
go
func (cr *ConflictResolver) addRecreateOpsToUnmergedChains(ctx context.Context, recreateOps []*createOp, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) ([]data.Path, error) { if len(recreateOps) == 0 { return nil, nil } // First create a lookup table that maps every block pointer in // every merged path to a corresponding key in the mergedPaths map. keys := make(map[data.BlockPointer]data.BlockPointer) for ptr, p := range mergedPaths { for _, node := range p.Path { keys[node.BlockPointer] = ptr } } var newUnmergedPaths []data.Path for _, rop := range recreateOps { // If rop.Dir.Unref is a merged most recent pointer, look up the // original. Otherwise rop.Dir.Unref is the original. Use the // original to look up the appropriate unmerged chain and stick // this op at the front. origTargetPtr, err := mergedChains.originalFromMostRecentOrSame(rop.Dir.Unref) if err != nil { return nil, err } chain, ok := unmergedChains.byOriginal[origTargetPtr] if !ok { return nil, fmt.Errorf("recreateOp for %v has no chain", origTargetPtr) } if len(chain.ops) == 0 { newUnmergedPaths = append(newUnmergedPaths, rop.getFinalPath()) } chain.ops = append([]op{rop}, chain.ops...) // Look up the corresponding unmerged most recent pointer, and // check whether there's a merged path for it yet. If not, // create one by looking it up in the lookup table (created // above) and taking the appropriate subpath. _, ok = mergedPaths[chain.mostRecent] if !ok { mergedMostRecent := chain.original if !mergedChains.isDeleted(chain.original) { if mChain, ok := mergedChains.byOriginal[chain.original]; ok { mergedMostRecent = mChain.mostRecent } } key, ok := keys[mergedMostRecent] if !ok { return nil, fmt.Errorf("Couldn't find a merged path "+ "containing the target of a recreate op: %v", mergedMostRecent) } currPath := mergedPaths[key] for currPath.TailPointer() != mergedMostRecent && currPath.HasValidParent() { currPath = *currPath.ParentPath() } mergedPaths[chain.mostRecent] = currPath } } return newUnmergedPaths, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "addRecreateOpsToUnmergedChains", "(", "ctx", "context", ".", "Context", ",", "recreateOps", "[", "]", "*", "createOp", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "mergedPaths", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "Path", ")", "(", "[", "]", "data", ".", "Path", ",", "error", ")", "{", "if", "len", "(", "recreateOps", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "// First create a lookup table that maps every block pointer in", "// every merged path to a corresponding key in the mergedPaths map.", "keys", ":=", "make", "(", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "BlockPointer", ")", "\n", "for", "ptr", ",", "p", ":=", "range", "mergedPaths", "{", "for", "_", ",", "node", ":=", "range", "p", ".", "Path", "{", "keys", "[", "node", ".", "BlockPointer", "]", "=", "ptr", "\n", "}", "\n", "}", "\n\n", "var", "newUnmergedPaths", "[", "]", "data", ".", "Path", "\n", "for", "_", ",", "rop", ":=", "range", "recreateOps", "{", "// If rop.Dir.Unref is a merged most recent pointer, look up the", "// original. Otherwise rop.Dir.Unref is the original. Use the", "// original to look up the appropriate unmerged chain and stick", "// this op at the front.", "origTargetPtr", ",", "err", ":=", "mergedChains", ".", "originalFromMostRecentOrSame", "(", "rop", ".", "Dir", ".", "Unref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "chain", ",", "ok", ":=", "unmergedChains", ".", "byOriginal", "[", "origTargetPtr", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "origTargetPtr", ")", "\n", "}", "\n", "if", "len", "(", "chain", ".", "ops", ")", "==", "0", "{", "newUnmergedPaths", "=", "append", "(", "newUnmergedPaths", ",", "rop", ".", "getFinalPath", "(", ")", ")", "\n", "}", "\n", "chain", ".", "ops", "=", "append", "(", "[", "]", "op", "{", "rop", "}", ",", "chain", ".", "ops", "...", ")", "\n\n", "// Look up the corresponding unmerged most recent pointer, and", "// check whether there's a merged path for it yet. If not,", "// create one by looking it up in the lookup table (created", "// above) and taking the appropriate subpath.", "_", ",", "ok", "=", "mergedPaths", "[", "chain", ".", "mostRecent", "]", "\n", "if", "!", "ok", "{", "mergedMostRecent", ":=", "chain", ".", "original", "\n", "if", "!", "mergedChains", ".", "isDeleted", "(", "chain", ".", "original", ")", "{", "if", "mChain", ",", "ok", ":=", "mergedChains", ".", "byOriginal", "[", "chain", ".", "original", "]", ";", "ok", "{", "mergedMostRecent", "=", "mChain", ".", "mostRecent", "\n", "}", "\n", "}", "\n", "key", ",", "ok", ":=", "keys", "[", "mergedMostRecent", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "mergedMostRecent", ")", "\n", "}", "\n", "currPath", ":=", "mergedPaths", "[", "key", "]", "\n", "for", "currPath", ".", "TailPointer", "(", ")", "!=", "mergedMostRecent", "&&", "currPath", ".", "HasValidParent", "(", ")", "{", "currPath", "=", "*", "currPath", ".", "ParentPath", "(", ")", "\n", "}", "\n", "mergedPaths", "[", "chain", ".", "mostRecent", "]", "=", "currPath", "\n", "}", "\n", "}", "\n\n", "return", "newUnmergedPaths", ",", "nil", "\n", "}" ]
// addRecreateOpsToUnmergedChains inserts each recreateOp, into its // appropriate unmerged chain, creating one if it doesn't exist yet. // It also adds entries as necessary to mergedPaths, and returns a // slice of new unmergedPaths to be added.
[ "addRecreateOpsToUnmergedChains", "inserts", "each", "recreateOp", "into", "its", "appropriate", "unmerged", "chain", "creating", "one", "if", "it", "doesn", "t", "exist", "yet", ".", "It", "also", "adds", "entries", "as", "necessary", "to", "mergedPaths", "and", "returns", "a", "slice", "of", "new", "unmergedPaths", "to", "be", "added", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L1349-L1415
161,357
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
addMergedRecreates
func (cr *ConflictResolver) addMergedRecreates(ctx context.Context, unmergedChains, mergedChains *crChains, mostRecentMergedWriterInfo writerInfo) error { for _, unmergedChain := range unmergedChains.byMostRecent { // First check for nodes that have been deleted in the unmerged // branch, but modified in the merged branch, and drop those // unmerged operations. for _, untypedOp := range unmergedChain.ops { ro, ok := untypedOp.(*rmOp) if !ok { continue } // Perhaps the rm target has been renamed somewhere else, // before eventually being deleted. In this case, we have // to look up the original by iterating over // renamedOriginals. if len(ro.Unrefs()) == 0 { for original, info := range unmergedChains.renamedOriginals { if info.originalOldParent == unmergedChain.original && info.oldName == ro.OldName && unmergedChains.isDeleted(original) { ro.AddUnrefBlock(original) break } } } for _, ptr := range ro.Unrefs() { unrefOriginal, err := unmergedChains.originalFromMostRecentOrSame(ptr) if err != nil { return err } if c, ok := mergedChains.byOriginal[unrefOriginal]; ok { ro.dropThis = true // Need to prepend a create here to the merged parent, // in order catch any conflicts. parentOriginal := unmergedChain.original name := ro.OldName if newParent, newName, ok := mergedChains.renamedParentAndName(unrefOriginal); ok { // It was renamed in the merged branch, so // recreate with the new parent and new name. parentOriginal = newParent name = newName } else if info, ok := unmergedChains.renamedOriginals[unrefOriginal]; ok { // It was only renamed in the old parent, so // use the old parent and original name. parentOriginal = info.originalOldParent name = info.oldName } chain, ok := mergedChains.byOriginal[parentOriginal] if !ok { return fmt.Errorf("Couldn't find chain for parent %v "+ "of merged entry %v we're trying to recreate", parentOriginal, unrefOriginal) } t := data.Dir if c.isFile() { // TODO: how to fix this up for executables // and symlinks? Only matters for checking // conflicts if something with the same name // is created on the unmerged branch. t = data.File } co, err := newCreateOp(name, chain.original, t) if err != nil { return err } err = co.Dir.setRef(chain.original) if err != nil { return err } co.AddRefBlock(c.mostRecent) co.setWriterInfo(mostRecentMergedWriterInfo) chain.ops = append([]op{co}, chain.ops...) cr.log.CDebugf(ctx, "Re-created rm'd merge-modified node "+ "%v with operation %s in parent %v", unrefOriginal, co, parentOriginal) } } } } return nil }
go
func (cr *ConflictResolver) addMergedRecreates(ctx context.Context, unmergedChains, mergedChains *crChains, mostRecentMergedWriterInfo writerInfo) error { for _, unmergedChain := range unmergedChains.byMostRecent { // First check for nodes that have been deleted in the unmerged // branch, but modified in the merged branch, and drop those // unmerged operations. for _, untypedOp := range unmergedChain.ops { ro, ok := untypedOp.(*rmOp) if !ok { continue } // Perhaps the rm target has been renamed somewhere else, // before eventually being deleted. In this case, we have // to look up the original by iterating over // renamedOriginals. if len(ro.Unrefs()) == 0 { for original, info := range unmergedChains.renamedOriginals { if info.originalOldParent == unmergedChain.original && info.oldName == ro.OldName && unmergedChains.isDeleted(original) { ro.AddUnrefBlock(original) break } } } for _, ptr := range ro.Unrefs() { unrefOriginal, err := unmergedChains.originalFromMostRecentOrSame(ptr) if err != nil { return err } if c, ok := mergedChains.byOriginal[unrefOriginal]; ok { ro.dropThis = true // Need to prepend a create here to the merged parent, // in order catch any conflicts. parentOriginal := unmergedChain.original name := ro.OldName if newParent, newName, ok := mergedChains.renamedParentAndName(unrefOriginal); ok { // It was renamed in the merged branch, so // recreate with the new parent and new name. parentOriginal = newParent name = newName } else if info, ok := unmergedChains.renamedOriginals[unrefOriginal]; ok { // It was only renamed in the old parent, so // use the old parent and original name. parentOriginal = info.originalOldParent name = info.oldName } chain, ok := mergedChains.byOriginal[parentOriginal] if !ok { return fmt.Errorf("Couldn't find chain for parent %v "+ "of merged entry %v we're trying to recreate", parentOriginal, unrefOriginal) } t := data.Dir if c.isFile() { // TODO: how to fix this up for executables // and symlinks? Only matters for checking // conflicts if something with the same name // is created on the unmerged branch. t = data.File } co, err := newCreateOp(name, chain.original, t) if err != nil { return err } err = co.Dir.setRef(chain.original) if err != nil { return err } co.AddRefBlock(c.mostRecent) co.setWriterInfo(mostRecentMergedWriterInfo) chain.ops = append([]op{co}, chain.ops...) cr.log.CDebugf(ctx, "Re-created rm'd merge-modified node "+ "%v with operation %s in parent %v", unrefOriginal, co, parentOriginal) } } } } return nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "addMergedRecreates", "(", "ctx", "context", ".", "Context", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "mostRecentMergedWriterInfo", "writerInfo", ")", "error", "{", "for", "_", ",", "unmergedChain", ":=", "range", "unmergedChains", ".", "byMostRecent", "{", "// First check for nodes that have been deleted in the unmerged", "// branch, but modified in the merged branch, and drop those", "// unmerged operations.", "for", "_", ",", "untypedOp", ":=", "range", "unmergedChain", ".", "ops", "{", "ro", ",", "ok", ":=", "untypedOp", ".", "(", "*", "rmOp", ")", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n\n", "// Perhaps the rm target has been renamed somewhere else,", "// before eventually being deleted. In this case, we have", "// to look up the original by iterating over", "// renamedOriginals.", "if", "len", "(", "ro", ".", "Unrefs", "(", ")", ")", "==", "0", "{", "for", "original", ",", "info", ":=", "range", "unmergedChains", ".", "renamedOriginals", "{", "if", "info", ".", "originalOldParent", "==", "unmergedChain", ".", "original", "&&", "info", ".", "oldName", "==", "ro", ".", "OldName", "&&", "unmergedChains", ".", "isDeleted", "(", "original", ")", "{", "ro", ".", "AddUnrefBlock", "(", "original", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "ptr", ":=", "range", "ro", ".", "Unrefs", "(", ")", "{", "unrefOriginal", ",", "err", ":=", "unmergedChains", ".", "originalFromMostRecentOrSame", "(", "ptr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "c", ",", "ok", ":=", "mergedChains", ".", "byOriginal", "[", "unrefOriginal", "]", ";", "ok", "{", "ro", ".", "dropThis", "=", "true", "\n", "// Need to prepend a create here to the merged parent,", "// in order catch any conflicts.", "parentOriginal", ":=", "unmergedChain", ".", "original", "\n", "name", ":=", "ro", ".", "OldName", "\n", "if", "newParent", ",", "newName", ",", "ok", ":=", "mergedChains", ".", "renamedParentAndName", "(", "unrefOriginal", ")", ";", "ok", "{", "// It was renamed in the merged branch, so", "// recreate with the new parent and new name.", "parentOriginal", "=", "newParent", "\n", "name", "=", "newName", "\n", "}", "else", "if", "info", ",", "ok", ":=", "unmergedChains", ".", "renamedOriginals", "[", "unrefOriginal", "]", ";", "ok", "{", "// It was only renamed in the old parent, so", "// use the old parent and original name.", "parentOriginal", "=", "info", ".", "originalOldParent", "\n", "name", "=", "info", ".", "oldName", "\n", "}", "\n", "chain", ",", "ok", ":=", "mergedChains", ".", "byOriginal", "[", "parentOriginal", "]", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", "+", "\"", "\"", ",", "parentOriginal", ",", "unrefOriginal", ")", "\n", "}", "\n", "t", ":=", "data", ".", "Dir", "\n", "if", "c", ".", "isFile", "(", ")", "{", "// TODO: how to fix this up for executables", "// and symlinks? Only matters for checking", "// conflicts if something with the same name", "// is created on the unmerged branch.", "t", "=", "data", ".", "File", "\n", "}", "\n", "co", ",", "err", ":=", "newCreateOp", "(", "name", ",", "chain", ".", "original", ",", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "co", ".", "Dir", ".", "setRef", "(", "chain", ".", "original", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "co", ".", "AddRefBlock", "(", "c", ".", "mostRecent", ")", "\n", "co", ".", "setWriterInfo", "(", "mostRecentMergedWriterInfo", ")", "\n", "chain", ".", "ops", "=", "append", "(", "[", "]", "op", "{", "co", "}", ",", "chain", ".", "ops", "...", ")", "\n", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", "+", "\"", "\"", ",", "unrefOriginal", ",", "co", ",", "parentOriginal", ")", "\n", "}", "\n", "}", "\n\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// addMergedRecreates drops any unmerged operations that remove a node // that was modified in the merged branch, and adds a create op to the // merged chain so that the node will be re-created locally.
[ "addMergedRecreates", "drops", "any", "unmerged", "operations", "that", "remove", "a", "node", "that", "was", "modified", "in", "the", "merged", "branch", "and", "adds", "a", "create", "op", "to", "the", "merged", "chain", "so", "that", "the", "node", "will", "be", "re", "-", "created", "locally", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L1994-L2082
161,358
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
getActionsToMerge
func (cr *ConflictResolver) getActionsToMerge( ctx context.Context, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) ( map[data.BlockPointer]crActionList, error) { actionMap := make(map[data.BlockPointer]crActionList) for unmergedMostRecent, unmergedChain := range unmergedChains.byMostRecent { original := unmergedChain.original // If this is a file that has been deleted in the merged // branch, a corresponding recreate op will take care of it, // no need to do anything here. // We don't need the "ok" value from this lookup because it's // fine to pass a nil mergedChain into crChain.getActionsToMerge. mergedChain := mergedChains.byOriginal[original] mergedPath, ok := mergedPaths[unmergedMostRecent] if !ok { // This most likely means that the file was created or // deleted in the unmerged branch and thus has no // corresponding merged path yet. continue } if !mergedPath.IsValid() { cr.log.CWarningf(ctx, "Ignoring invalid merged path for %v "+ "(original=%v)", unmergedMostRecent, original) continue } actions, err := unmergedChain.getActionsToMerge( ctx, cr.config.ConflictRenamer(), mergedPath, mergedChain) if err != nil { return nil, err } if len(actions) > 0 { actionMap[mergedPath.TailPointer()] = actions } } return actionMap, nil }
go
func (cr *ConflictResolver) getActionsToMerge( ctx context.Context, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) ( map[data.BlockPointer]crActionList, error) { actionMap := make(map[data.BlockPointer]crActionList) for unmergedMostRecent, unmergedChain := range unmergedChains.byMostRecent { original := unmergedChain.original // If this is a file that has been deleted in the merged // branch, a corresponding recreate op will take care of it, // no need to do anything here. // We don't need the "ok" value from this lookup because it's // fine to pass a nil mergedChain into crChain.getActionsToMerge. mergedChain := mergedChains.byOriginal[original] mergedPath, ok := mergedPaths[unmergedMostRecent] if !ok { // This most likely means that the file was created or // deleted in the unmerged branch and thus has no // corresponding merged path yet. continue } if !mergedPath.IsValid() { cr.log.CWarningf(ctx, "Ignoring invalid merged path for %v "+ "(original=%v)", unmergedMostRecent, original) continue } actions, err := unmergedChain.getActionsToMerge( ctx, cr.config.ConflictRenamer(), mergedPath, mergedChain) if err != nil { return nil, err } if len(actions) > 0 { actionMap[mergedPath.TailPointer()] = actions } } return actionMap, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "getActionsToMerge", "(", "ctx", "context", ".", "Context", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "mergedPaths", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "Path", ")", "(", "map", "[", "data", ".", "BlockPointer", "]", "crActionList", ",", "error", ")", "{", "actionMap", ":=", "make", "(", "map", "[", "data", ".", "BlockPointer", "]", "crActionList", ")", "\n", "for", "unmergedMostRecent", ",", "unmergedChain", ":=", "range", "unmergedChains", ".", "byMostRecent", "{", "original", ":=", "unmergedChain", ".", "original", "\n", "// If this is a file that has been deleted in the merged", "// branch, a corresponding recreate op will take care of it,", "// no need to do anything here.", "// We don't need the \"ok\" value from this lookup because it's", "// fine to pass a nil mergedChain into crChain.getActionsToMerge.", "mergedChain", ":=", "mergedChains", ".", "byOriginal", "[", "original", "]", "\n", "mergedPath", ",", "ok", ":=", "mergedPaths", "[", "unmergedMostRecent", "]", "\n", "if", "!", "ok", "{", "// This most likely means that the file was created or", "// deleted in the unmerged branch and thus has no", "// corresponding merged path yet.", "continue", "\n", "}", "\n", "if", "!", "mergedPath", ".", "IsValid", "(", ")", "{", "cr", ".", "log", ".", "CWarningf", "(", "ctx", ",", "\"", "\"", "+", "\"", "\"", ",", "unmergedMostRecent", ",", "original", ")", "\n", "continue", "\n", "}", "\n\n", "actions", ",", "err", ":=", "unmergedChain", ".", "getActionsToMerge", "(", "ctx", ",", "cr", ".", "config", ".", "ConflictRenamer", "(", ")", ",", "mergedPath", ",", "mergedChain", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "actions", ")", ">", "0", "{", "actionMap", "[", "mergedPath", ".", "TailPointer", "(", ")", "]", "=", "actions", "\n", "}", "\n", "}", "\n\n", "return", "actionMap", ",", "nil", "\n", "}" ]
// getActionsToMerge returns the set of actions needed to merge each // unmerged chain of operations, in a map keyed by the tail pointer of // the corresponding merged path.
[ "getActionsToMerge", "returns", "the", "set", "of", "actions", "needed", "to", "merge", "each", "unmerged", "chain", "of", "operations", "in", "a", "map", "keyed", "by", "the", "tail", "pointer", "of", "the", "corresponding", "merged", "path", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L2087-L2127
161,359
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
createResolvedMD
func (cr *ConflictResolver) createResolvedMD(ctx context.Context, lState *kbfssync.LockState, unmergedPaths []data.Path, unmergedChains, mergedChains *crChains, mostRecentMergedMD ImmutableRootMetadata) (*RootMetadata, error) { err := cr.checkDone(ctx) if err != nil { return nil, err } newMD, err := mostRecentMergedMD.MakeSuccessor( ctx, cr.config.MetadataVersion(), cr.config.Codec(), cr.config.KeyManager(), cr.config.KBPKI(), cr.config.KBPKI(), cr.config, mostRecentMergedMD.MdID(), true) if err != nil { return nil, err } var newPaths []data.Path for original, chain := range unmergedChains.byOriginal { added := false for i, op := range chain.ops { if cop, ok := op.(*createOp); ok { // We need to add in any creates that happened // within newly-created directories (which aren't // being merged with other newly-created directories), // to ensure that the overall Refs are correct and // that future CR processes can check those create ops // for conflicts. if unmergedChains.isCreated(original) && !mergedChains.isCreated(original) { // Shallowly copy the create op and update its // directory to the most recent pointer -- this won't // work with the usual revert ops process because that // skips chains which are newly-created within this // branch. newCreateOp := *cop newCreateOp.Dir, err = makeBlockUpdate( chain.mostRecent, chain.mostRecent) if err != nil { return nil, err } chain.ops[i] = &newCreateOp if !added { newPaths = append(newPaths, data.Path{ FolderBranch: cr.fbo.folderBranch, Path: []data.PathNode{{ BlockPointer: chain.mostRecent}}, }) added = true } } if cop.Type == data.Dir || len(cop.Refs()) == 0 { continue } // Add any direct file blocks too into each create op, // which originated in later unmerged syncs. ptr, err := unmergedChains.mostRecentFromOriginalOrSame(cop.Refs()[0]) if err != nil { return nil, err } trackSyncPtrChangesInCreate( ptr, chain, unmergedChains, cop.NewName) } } } if len(newPaths) > 0 { // Put the new paths at the beginning so they are processed // last in sorted order. unmergedPaths = append(newPaths, unmergedPaths...) } ops, err := cr.makeRevertedOps( ctx, lState, unmergedPaths, unmergedChains, mergedChains) if err != nil { return nil, err } cr.log.CDebugf(ctx, "Remote notifications: %v", ops) for _, op := range ops { cr.log.CDebugf(ctx, "%s: refs %v", op, op.Refs()) newMD.AddOp(op) } // Add a final dummy operation to collect all of the block updates. newMD.AddOp(newResolutionOp()) return newMD, nil }
go
func (cr *ConflictResolver) createResolvedMD(ctx context.Context, lState *kbfssync.LockState, unmergedPaths []data.Path, unmergedChains, mergedChains *crChains, mostRecentMergedMD ImmutableRootMetadata) (*RootMetadata, error) { err := cr.checkDone(ctx) if err != nil { return nil, err } newMD, err := mostRecentMergedMD.MakeSuccessor( ctx, cr.config.MetadataVersion(), cr.config.Codec(), cr.config.KeyManager(), cr.config.KBPKI(), cr.config.KBPKI(), cr.config, mostRecentMergedMD.MdID(), true) if err != nil { return nil, err } var newPaths []data.Path for original, chain := range unmergedChains.byOriginal { added := false for i, op := range chain.ops { if cop, ok := op.(*createOp); ok { // We need to add in any creates that happened // within newly-created directories (which aren't // being merged with other newly-created directories), // to ensure that the overall Refs are correct and // that future CR processes can check those create ops // for conflicts. if unmergedChains.isCreated(original) && !mergedChains.isCreated(original) { // Shallowly copy the create op and update its // directory to the most recent pointer -- this won't // work with the usual revert ops process because that // skips chains which are newly-created within this // branch. newCreateOp := *cop newCreateOp.Dir, err = makeBlockUpdate( chain.mostRecent, chain.mostRecent) if err != nil { return nil, err } chain.ops[i] = &newCreateOp if !added { newPaths = append(newPaths, data.Path{ FolderBranch: cr.fbo.folderBranch, Path: []data.PathNode{{ BlockPointer: chain.mostRecent}}, }) added = true } } if cop.Type == data.Dir || len(cop.Refs()) == 0 { continue } // Add any direct file blocks too into each create op, // which originated in later unmerged syncs. ptr, err := unmergedChains.mostRecentFromOriginalOrSame(cop.Refs()[0]) if err != nil { return nil, err } trackSyncPtrChangesInCreate( ptr, chain, unmergedChains, cop.NewName) } } } if len(newPaths) > 0 { // Put the new paths at the beginning so they are processed // last in sorted order. unmergedPaths = append(newPaths, unmergedPaths...) } ops, err := cr.makeRevertedOps( ctx, lState, unmergedPaths, unmergedChains, mergedChains) if err != nil { return nil, err } cr.log.CDebugf(ctx, "Remote notifications: %v", ops) for _, op := range ops { cr.log.CDebugf(ctx, "%s: refs %v", op, op.Refs()) newMD.AddOp(op) } // Add a final dummy operation to collect all of the block updates. newMD.AddOp(newResolutionOp()) return newMD, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "createResolvedMD", "(", "ctx", "context", ".", "Context", ",", "lState", "*", "kbfssync", ".", "LockState", ",", "unmergedPaths", "[", "]", "data", ".", "Path", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "mostRecentMergedMD", "ImmutableRootMetadata", ")", "(", "*", "RootMetadata", ",", "error", ")", "{", "err", ":=", "cr", ".", "checkDone", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "newMD", ",", "err", ":=", "mostRecentMergedMD", ".", "MakeSuccessor", "(", "ctx", ",", "cr", ".", "config", ".", "MetadataVersion", "(", ")", ",", "cr", ".", "config", ".", "Codec", "(", ")", ",", "cr", ".", "config", ".", "KeyManager", "(", ")", ",", "cr", ".", "config", ".", "KBPKI", "(", ")", ",", "cr", ".", "config", ".", "KBPKI", "(", ")", ",", "cr", ".", "config", ",", "mostRecentMergedMD", ".", "MdID", "(", ")", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "newPaths", "[", "]", "data", ".", "Path", "\n", "for", "original", ",", "chain", ":=", "range", "unmergedChains", ".", "byOriginal", "{", "added", ":=", "false", "\n", "for", "i", ",", "op", ":=", "range", "chain", ".", "ops", "{", "if", "cop", ",", "ok", ":=", "op", ".", "(", "*", "createOp", ")", ";", "ok", "{", "// We need to add in any creates that happened", "// within newly-created directories (which aren't", "// being merged with other newly-created directories),", "// to ensure that the overall Refs are correct and", "// that future CR processes can check those create ops", "// for conflicts.", "if", "unmergedChains", ".", "isCreated", "(", "original", ")", "&&", "!", "mergedChains", ".", "isCreated", "(", "original", ")", "{", "// Shallowly copy the create op and update its", "// directory to the most recent pointer -- this won't", "// work with the usual revert ops process because that", "// skips chains which are newly-created within this", "// branch.", "newCreateOp", ":=", "*", "cop", "\n", "newCreateOp", ".", "Dir", ",", "err", "=", "makeBlockUpdate", "(", "chain", ".", "mostRecent", ",", "chain", ".", "mostRecent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "chain", ".", "ops", "[", "i", "]", "=", "&", "newCreateOp", "\n", "if", "!", "added", "{", "newPaths", "=", "append", "(", "newPaths", ",", "data", ".", "Path", "{", "FolderBranch", ":", "cr", ".", "fbo", ".", "folderBranch", ",", "Path", ":", "[", "]", "data", ".", "PathNode", "{", "{", "BlockPointer", ":", "chain", ".", "mostRecent", "}", "}", ",", "}", ")", "\n", "added", "=", "true", "\n", "}", "\n", "}", "\n", "if", "cop", ".", "Type", "==", "data", ".", "Dir", "||", "len", "(", "cop", ".", "Refs", "(", ")", ")", "==", "0", "{", "continue", "\n", "}", "\n", "// Add any direct file blocks too into each create op,", "// which originated in later unmerged syncs.", "ptr", ",", "err", ":=", "unmergedChains", ".", "mostRecentFromOriginalOrSame", "(", "cop", ".", "Refs", "(", ")", "[", "0", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "trackSyncPtrChangesInCreate", "(", "ptr", ",", "chain", ",", "unmergedChains", ",", "cop", ".", "NewName", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "newPaths", ")", ">", "0", "{", "// Put the new paths at the beginning so they are processed", "// last in sorted order.", "unmergedPaths", "=", "append", "(", "newPaths", ",", "unmergedPaths", "...", ")", "\n", "}", "\n\n", "ops", ",", "err", ":=", "cr", ".", "makeRevertedOps", "(", "ctx", ",", "lState", ",", "unmergedPaths", ",", "unmergedChains", ",", "mergedChains", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "ops", ")", "\n", "for", "_", ",", "op", ":=", "range", "ops", "{", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "op", ",", "op", ".", "Refs", "(", ")", ")", "\n", "newMD", ".", "AddOp", "(", "op", ")", "\n", "}", "\n\n", "// Add a final dummy operation to collect all of the block updates.", "newMD", ".", "AddOp", "(", "newResolutionOp", "(", ")", ")", "\n\n", "return", "newMD", ",", "nil", "\n", "}" ]
// createResolvedMD creates a MD update that will be merged into the // main folder as the resolving commit. It contains all of the // unmerged operations, as well as a "dummy" operation at the end // which will catch all of the BlockPointer updates. A later phase // will move all of those updates into their proper locations within // the other operations.
[ "createResolvedMD", "creates", "a", "MD", "update", "that", "will", "be", "merged", "into", "the", "main", "folder", "as", "the", "resolving", "commit", ".", "It", "contains", "all", "of", "the", "unmerged", "operations", "as", "well", "as", "a", "dummy", "operation", "at", "the", "end", "which", "will", "catch", "all", "of", "the", "BlockPointer", "updates", ".", "A", "later", "phase", "will", "move", "all", "of", "those", "updates", "into", "their", "proper", "locations", "within", "the", "other", "operations", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L2703-L2791
161,360
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
makePostResolutionPaths
func (cr *ConflictResolver) makePostResolutionPaths(ctx context.Context, md *RootMetadata, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) (map[data.BlockPointer]data.Path, error) { err := cr.checkDone(ctx) if err != nil { return nil, err } session, err := cr.config.KBPKI().GetCurrentSession(ctx) if err != nil { return nil, err } // No need to run any identifies on these chains, since we // have already finished all actions. resolvedChains, err := newCRChains( ctx, cr.config.Codec(), cr.config, []chainMetadata{rootMetadataWithKeyAndTimestamp{md, session.VerifyingKey, cr.config.Clock().Now()}}, &cr.fbo.blocks, false) if err != nil { return nil, err } // If there are no renames, we don't need to fix any of the paths if len(resolvedChains.renamedOriginals) == 0 { return mergedPaths, nil } resolvedPaths := make(map[data.BlockPointer]data.Path) for ptr, oldP := range mergedPaths { p, err := cr.resolveOnePath(ctx, ptr, unmergedChains, mergedChains, resolvedChains, mergedPaths, resolvedPaths) if err != nil { return nil, err } cr.log.CDebugf(ctx, "Resolved path for %v from %v to %v", ptr, oldP.Path, p.Path) } return resolvedPaths, nil }
go
func (cr *ConflictResolver) makePostResolutionPaths(ctx context.Context, md *RootMetadata, unmergedChains, mergedChains *crChains, mergedPaths map[data.BlockPointer]data.Path) (map[data.BlockPointer]data.Path, error) { err := cr.checkDone(ctx) if err != nil { return nil, err } session, err := cr.config.KBPKI().GetCurrentSession(ctx) if err != nil { return nil, err } // No need to run any identifies on these chains, since we // have already finished all actions. resolvedChains, err := newCRChains( ctx, cr.config.Codec(), cr.config, []chainMetadata{rootMetadataWithKeyAndTimestamp{md, session.VerifyingKey, cr.config.Clock().Now()}}, &cr.fbo.blocks, false) if err != nil { return nil, err } // If there are no renames, we don't need to fix any of the paths if len(resolvedChains.renamedOriginals) == 0 { return mergedPaths, nil } resolvedPaths := make(map[data.BlockPointer]data.Path) for ptr, oldP := range mergedPaths { p, err := cr.resolveOnePath(ctx, ptr, unmergedChains, mergedChains, resolvedChains, mergedPaths, resolvedPaths) if err != nil { return nil, err } cr.log.CDebugf(ctx, "Resolved path for %v from %v to %v", ptr, oldP.Path, p.Path) } return resolvedPaths, nil }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "makePostResolutionPaths", "(", "ctx", "context", ".", "Context", ",", "md", "*", "RootMetadata", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "mergedPaths", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "Path", ")", "(", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "Path", ",", "error", ")", "{", "err", ":=", "cr", ".", "checkDone", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "session", ",", "err", ":=", "cr", ".", "config", ".", "KBPKI", "(", ")", ".", "GetCurrentSession", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// No need to run any identifies on these chains, since we", "// have already finished all actions.", "resolvedChains", ",", "err", ":=", "newCRChains", "(", "ctx", ",", "cr", ".", "config", ".", "Codec", "(", ")", ",", "cr", ".", "config", ",", "[", "]", "chainMetadata", "{", "rootMetadataWithKeyAndTimestamp", "{", "md", ",", "session", ".", "VerifyingKey", ",", "cr", ".", "config", ".", "Clock", "(", ")", ".", "Now", "(", ")", "}", "}", ",", "&", "cr", ".", "fbo", ".", "blocks", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// If there are no renames, we don't need to fix any of the paths", "if", "len", "(", "resolvedChains", ".", "renamedOriginals", ")", "==", "0", "{", "return", "mergedPaths", ",", "nil", "\n", "}", "\n\n", "resolvedPaths", ":=", "make", "(", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "Path", ")", "\n", "for", "ptr", ",", "oldP", ":=", "range", "mergedPaths", "{", "p", ",", "err", ":=", "cr", ".", "resolveOnePath", "(", "ctx", ",", "ptr", ",", "unmergedChains", ",", "mergedChains", ",", "resolvedChains", ",", "mergedPaths", ",", "resolvedPaths", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "ptr", ",", "oldP", ".", "Path", ",", "p", ".", "Path", ")", "\n", "}", "\n\n", "return", "resolvedPaths", ",", "nil", "\n", "}" ]
// makePostResolutionPaths returns the full paths to each unmerged // pointer, taking into account any rename operations that occurred in // the merged branch.
[ "makePostResolutionPaths", "returns", "the", "full", "paths", "to", "each", "unmerged", "pointer", "taking", "into", "account", "any", "rename", "operations", "that", "occurred", "in", "the", "merged", "branch", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L2907-L2948
161,361
keybase/client
go/kbfs/libkbfs/conflict_resolver.go
finalizeResolution
func (cr *ConflictResolver) finalizeResolution(ctx context.Context, lState *kbfssync.LockState, md *RootMetadata, unmergedChains, mergedChains *crChains, updates map[data.BlockPointer]data.BlockPointer, bps blockPutState, blocksToDelete []kbfsblock.ID, writerLocked bool) error { err := cr.checkDone(ctx) if err != nil { return err } // Fix up all the block pointers in the merged ops to work well // for local notifications. Make a dummy op at the beginning to // convert all the merged most recent pointers into unmerged most // recent pointers. newOps, err := cr.getOpsForLocalNotification( ctx, lState, md, unmergedChains, mergedChains, updates) if err != nil { return err } cr.log.CDebugf(ctx, "Local notifications: %v", newOps) if writerLocked { return cr.fbo.finalizeResolutionLocked( ctx, lState, md, bps, newOps, blocksToDelete) } return cr.fbo.finalizeResolution( ctx, lState, md, bps, newOps, blocksToDelete) }
go
func (cr *ConflictResolver) finalizeResolution(ctx context.Context, lState *kbfssync.LockState, md *RootMetadata, unmergedChains, mergedChains *crChains, updates map[data.BlockPointer]data.BlockPointer, bps blockPutState, blocksToDelete []kbfsblock.ID, writerLocked bool) error { err := cr.checkDone(ctx) if err != nil { return err } // Fix up all the block pointers in the merged ops to work well // for local notifications. Make a dummy op at the beginning to // convert all the merged most recent pointers into unmerged most // recent pointers. newOps, err := cr.getOpsForLocalNotification( ctx, lState, md, unmergedChains, mergedChains, updates) if err != nil { return err } cr.log.CDebugf(ctx, "Local notifications: %v", newOps) if writerLocked { return cr.fbo.finalizeResolutionLocked( ctx, lState, md, bps, newOps, blocksToDelete) } return cr.fbo.finalizeResolution( ctx, lState, md, bps, newOps, blocksToDelete) }
[ "func", "(", "cr", "*", "ConflictResolver", ")", "finalizeResolution", "(", "ctx", "context", ".", "Context", ",", "lState", "*", "kbfssync", ".", "LockState", ",", "md", "*", "RootMetadata", ",", "unmergedChains", ",", "mergedChains", "*", "crChains", ",", "updates", "map", "[", "data", ".", "BlockPointer", "]", "data", ".", "BlockPointer", ",", "bps", "blockPutState", ",", "blocksToDelete", "[", "]", "kbfsblock", ".", "ID", ",", "writerLocked", "bool", ")", "error", "{", "err", ":=", "cr", ".", "checkDone", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Fix up all the block pointers in the merged ops to work well", "// for local notifications. Make a dummy op at the beginning to", "// convert all the merged most recent pointers into unmerged most", "// recent pointers.", "newOps", ",", "err", ":=", "cr", ".", "getOpsForLocalNotification", "(", "ctx", ",", "lState", ",", "md", ",", "unmergedChains", ",", "mergedChains", ",", "updates", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "cr", ".", "log", ".", "CDebugf", "(", "ctx", ",", "\"", "\"", ",", "newOps", ")", "\n\n", "if", "writerLocked", "{", "return", "cr", ".", "fbo", ".", "finalizeResolutionLocked", "(", "ctx", ",", "lState", ",", "md", ",", "bps", ",", "newOps", ",", "blocksToDelete", ")", "\n", "}", "\n", "return", "cr", ".", "fbo", ".", "finalizeResolution", "(", "ctx", ",", "lState", ",", "md", ",", "bps", ",", "newOps", ",", "blocksToDelete", ")", "\n", "}" ]
// finalizeResolution finishes the resolution process, making the // resolution visible to any nodes on the merged branch, and taking // the local node out of staged mode.
[ "finalizeResolution", "finishes", "the", "resolution", "process", "making", "the", "resolution", "visible", "to", "any", "nodes", "on", "the", "merged", "branch", "and", "taking", "the", "local", "node", "out", "of", "staged", "mode", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/conflict_resolver.go#L3076-L3105
161,362
keybase/client
go/kbfs/tlfhandle/path.go
BuildCanonicalPathForTlfType
func BuildCanonicalPathForTlfType(t tlf.Type, paths ...string) string { var pathType PathType switch t { case tlf.Private: pathType = PrivatePathType case tlf.Public: pathType = PublicPathType case tlf.SingleTeam: pathType = SingleTeamPathType default: panic(fmt.Sprintf("Unknown tlf path type: %d", t)) } return BuildCanonicalPath(pathType, paths...) }
go
func BuildCanonicalPathForTlfType(t tlf.Type, paths ...string) string { var pathType PathType switch t { case tlf.Private: pathType = PrivatePathType case tlf.Public: pathType = PublicPathType case tlf.SingleTeam: pathType = SingleTeamPathType default: panic(fmt.Sprintf("Unknown tlf path type: %d", t)) } return BuildCanonicalPath(pathType, paths...) }
[ "func", "BuildCanonicalPathForTlfType", "(", "t", "tlf", ".", "Type", ",", "paths", "...", "string", ")", "string", "{", "var", "pathType", "PathType", "\n", "switch", "t", "{", "case", "tlf", ".", "Private", ":", "pathType", "=", "PrivatePathType", "\n", "case", "tlf", ".", "Public", ":", "pathType", "=", "PublicPathType", "\n", "case", "tlf", ".", "SingleTeam", ":", "pathType", "=", "SingleTeamPathType", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ")", ")", "\n", "}", "\n\n", "return", "BuildCanonicalPath", "(", "pathType", ",", "paths", "...", ")", "\n", "}" ]
// BuildCanonicalPathForTlfType is like BuildCanonicalPath, but accepts a // tlf.Type instead of PathhType.
[ "BuildCanonicalPathForTlfType", "is", "like", "BuildCanonicalPath", "but", "accepts", "a", "tlf", ".", "Type", "instead", "of", "PathhType", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlfhandle/path.go#L53-L67
161,363
keybase/client
go/kbfs/tlfhandle/path.go
BuildCanonicalPathForTlfName
func BuildCanonicalPathForTlfName(t tlf.Type, tlfName tlf.CanonicalName) string { return BuildCanonicalPathForTlfType(t, string(tlfName)) }
go
func BuildCanonicalPathForTlfName(t tlf.Type, tlfName tlf.CanonicalName) string { return BuildCanonicalPathForTlfType(t, string(tlfName)) }
[ "func", "BuildCanonicalPathForTlfName", "(", "t", "tlf", ".", "Type", ",", "tlfName", "tlf", ".", "CanonicalName", ")", "string", "{", "return", "BuildCanonicalPathForTlfType", "(", "t", ",", "string", "(", "tlfName", ")", ")", "\n", "}" ]
// BuildCanonicalPathForTlfName returns a canonical path for a tlf.
[ "BuildCanonicalPathForTlfName", "returns", "a", "canonical", "path", "for", "a", "tlf", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlfhandle/path.go#L70-L72
161,364
keybase/client
go/kbfs/tlfhandle/path.go
BuildCanonicalPathForTlf
func BuildCanonicalPathForTlf(tlf tlf.ID, paths ...string) string { return BuildCanonicalPathForTlfType(tlf.Type(), paths...) }
go
func BuildCanonicalPathForTlf(tlf tlf.ID, paths ...string) string { return BuildCanonicalPathForTlfType(tlf.Type(), paths...) }
[ "func", "BuildCanonicalPathForTlf", "(", "tlf", "tlf", ".", "ID", ",", "paths", "...", "string", ")", "string", "{", "return", "BuildCanonicalPathForTlfType", "(", "tlf", ".", "Type", "(", ")", ",", "paths", "...", ")", "\n", "}" ]
// BuildCanonicalPathForTlf returns a canonical path for a tlf. Although tlf // identifies a TLF, paths should still include the TLF name. This function // does not try to canonicalize TLF names.
[ "BuildCanonicalPathForTlf", "returns", "a", "canonical", "path", "for", "a", "tlf", ".", "Although", "tlf", "identifies", "a", "TLF", "paths", "should", "still", "include", "the", "TLF", "name", ".", "This", "function", "does", "not", "try", "to", "canonicalize", "TLF", "names", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlfhandle/path.go#L77-L79
161,365
keybase/client
go/protocol/gregor1/incoming.go
ConsumeMessageMulti
func (c IncomingClient) ConsumeMessageMulti(ctx context.Context, __arg ConsumeMessageMultiArg) (err error) { err = c.Cli.CallCompressed(ctx, "gregor.1.incoming.consumeMessageMulti", []interface{}{__arg}, nil, rpc.CompressionGzip) return }
go
func (c IncomingClient) ConsumeMessageMulti(ctx context.Context, __arg ConsumeMessageMultiArg) (err error) { err = c.Cli.CallCompressed(ctx, "gregor.1.incoming.consumeMessageMulti", []interface{}{__arg}, nil, rpc.CompressionGzip) return }
[ "func", "(", "c", "IncomingClient", ")", "ConsumeMessageMulti", "(", "ctx", "context", ".", "Context", ",", "__arg", "ConsumeMessageMultiArg", ")", "(", "err", "error", ")", "{", "err", "=", "c", ".", "Cli", ".", "CallCompressed", "(", "ctx", ",", "\"", "\"", ",", "[", "]", "interface", "{", "}", "{", "__arg", "}", ",", "nil", ",", "rpc", ".", "CompressionGzip", ")", "\n", "return", "\n", "}" ]
// consumeMessageMulti will take msg and consume it for all the users listed // in uids. This is so a gregor client can send the same message to many UIDs // with one call, as opposed to calling consumeMessage for each UID.
[ "consumeMessageMulti", "will", "take", "msg", "and", "consume", "it", "for", "all", "the", "users", "listed", "in", "uids", ".", "This", "is", "so", "a", "gregor", "client", "can", "send", "the", "same", "message", "to", "many", "UIDs", "with", "one", "call", "as", "opposed", "to", "calling", "consumeMessage", "for", "each", "UID", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/protocol/gregor1/incoming.go#L321-L324
161,366
keybase/client
go/client/cmd_pgp_gen.go
Run
func (v *CmdPGPGen) Run() (err error) { protocols := []rpc.Protocol{ NewSecretUIProtocol(v.G()), } cli, err := GetPGPClient(v.G()) if err != nil { return err } user, err := GetUserClient(v.G()) if err != nil { return err } if err = RegisterProtocolsWithContext(protocols, v.G()); err != nil { return err } // Prompt for user IDs if none given on command line if len(v.arg.Gen.PGPUids) == 0 { if err = v.propmptPGPIDs(); err != nil { return err } } else if err = v.arg.Gen.CreatePGPIDs(); err != nil { return err } hasRandomPw, err := user.LoadHasRandomPw(context.TODO(), keybase1.LoadHasRandomPwArg{}) if err != nil { return err } if !hasRandomPw { v.arg.PushSecret, err = v.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorPGPGenPushSecret, "Push an encrypted copy of your new secret key to the Keybase.io server?", libkb.PromptDefaultYes) if err != nil { return err } } if v.arg.DoExport { v.arg.ExportEncrypted, err = v.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorPGPGenEncryptSecret, "When exporting to the GnuPG keychain, encrypt private keys with a passphrase?", libkb.PromptDefaultYes) if err != nil { return err } } err = cli.PGPKeyGen(context.TODO(), v.arg.Export()) err = AddPGPMultiInstructions(err) return err }
go
func (v *CmdPGPGen) Run() (err error) { protocols := []rpc.Protocol{ NewSecretUIProtocol(v.G()), } cli, err := GetPGPClient(v.G()) if err != nil { return err } user, err := GetUserClient(v.G()) if err != nil { return err } if err = RegisterProtocolsWithContext(protocols, v.G()); err != nil { return err } // Prompt for user IDs if none given on command line if len(v.arg.Gen.PGPUids) == 0 { if err = v.propmptPGPIDs(); err != nil { return err } } else if err = v.arg.Gen.CreatePGPIDs(); err != nil { return err } hasRandomPw, err := user.LoadHasRandomPw(context.TODO(), keybase1.LoadHasRandomPwArg{}) if err != nil { return err } if !hasRandomPw { v.arg.PushSecret, err = v.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorPGPGenPushSecret, "Push an encrypted copy of your new secret key to the Keybase.io server?", libkb.PromptDefaultYes) if err != nil { return err } } if v.arg.DoExport { v.arg.ExportEncrypted, err = v.G().UI.GetTerminalUI().PromptYesNo(PromptDescriptorPGPGenEncryptSecret, "When exporting to the GnuPG keychain, encrypt private keys with a passphrase?", libkb.PromptDefaultYes) if err != nil { return err } } err = cli.PGPKeyGen(context.TODO(), v.arg.Export()) err = AddPGPMultiInstructions(err) return err }
[ "func", "(", "v", "*", "CmdPGPGen", ")", "Run", "(", ")", "(", "err", "error", ")", "{", "protocols", ":=", "[", "]", "rpc", ".", "Protocol", "{", "NewSecretUIProtocol", "(", "v", ".", "G", "(", ")", ")", ",", "}", "\n", "cli", ",", "err", ":=", "GetPGPClient", "(", "v", ".", "G", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "user", ",", "err", ":=", "GetUserClient", "(", "v", ".", "G", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", "=", "RegisterProtocolsWithContext", "(", "protocols", ",", "v", ".", "G", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Prompt for user IDs if none given on command line", "if", "len", "(", "v", ".", "arg", ".", "Gen", ".", "PGPUids", ")", "==", "0", "{", "if", "err", "=", "v", ".", "propmptPGPIDs", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "if", "err", "=", "v", ".", "arg", ".", "Gen", ".", "CreatePGPIDs", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "hasRandomPw", ",", "err", ":=", "user", ".", "LoadHasRandomPw", "(", "context", ".", "TODO", "(", ")", ",", "keybase1", ".", "LoadHasRandomPwArg", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "hasRandomPw", "{", "v", ".", "arg", ".", "PushSecret", ",", "err", "=", "v", ".", "G", "(", ")", ".", "UI", ".", "GetTerminalUI", "(", ")", ".", "PromptYesNo", "(", "PromptDescriptorPGPGenPushSecret", ",", "\"", "\"", ",", "libkb", ".", "PromptDefaultYes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "v", ".", "arg", ".", "DoExport", "{", "v", ".", "arg", ".", "ExportEncrypted", ",", "err", "=", "v", ".", "G", "(", ")", ".", "UI", ".", "GetTerminalUI", "(", ")", ".", "PromptYesNo", "(", "PromptDescriptorPGPGenEncryptSecret", ",", "\"", "\"", ",", "libkb", ".", "PromptDefaultYes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "err", "=", "cli", ".", "PGPKeyGen", "(", "context", ".", "TODO", "(", ")", ",", "v", ".", "arg", ".", "Export", "(", ")", ")", "\n", "err", "=", "AddPGPMultiInstructions", "(", "err", ")", "\n", "return", "err", "\n", "}" ]
// Why use CreatePGPIDs rather than MakeAllIds?
[ "Why", "use", "CreatePGPIDs", "rather", "than", "MakeAllIds?" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_pgp_gen.go#L45-L91
161,367
keybase/client
go/kbfs/idutil/data_types.go
ResetInfo
func (rki RevokedKeyInfo) ResetInfo() (keybase1.Seqno, bool) { return rki.resetSeqno, rki.isReset }
go
func (rki RevokedKeyInfo) ResetInfo() (keybase1.Seqno, bool) { return rki.resetSeqno, rki.isReset }
[ "func", "(", "rki", "RevokedKeyInfo", ")", "ResetInfo", "(", ")", "(", "keybase1", ".", "Seqno", ",", "bool", ")", "{", "return", "rki", ".", "resetSeqno", ",", "rki", ".", "isReset", "\n", "}" ]
// ResetInfo returns, if this key belongs to an account before it was // reset, data about that reset.
[ "ResetInfo", "returns", "if", "this", "key", "belongs", "to", "an", "account", "before", "it", "was", "reset", "data", "about", "that", "reset", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/idutil/data_types.go#L61-L63
161,368
keybase/client
go/kbfs/idutil/data_types.go
SetResetInfo
func (rki *RevokedKeyInfo) SetResetInfo(seqno keybase1.Seqno, isReset bool) { rki.resetSeqno = seqno rki.isReset = isReset }
go
func (rki *RevokedKeyInfo) SetResetInfo(seqno keybase1.Seqno, isReset bool) { rki.resetSeqno = seqno rki.isReset = isReset }
[ "func", "(", "rki", "*", "RevokedKeyInfo", ")", "SetResetInfo", "(", "seqno", "keybase1", ".", "Seqno", ",", "isReset", "bool", ")", "{", "rki", ".", "resetSeqno", "=", "seqno", "\n", "rki", ".", "isReset", "=", "isReset", "\n", "}" ]
// SetResetInfo sets, if this key belongs to an account before it was // reset, data about that reset.
[ "SetResetInfo", "sets", "if", "this", "key", "belongs", "to", "an", "account", "before", "it", "was", "reset", "data", "about", "that", "reset", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/idutil/data_types.go#L67-L70
161,369
keybase/client
go/kbfs/idutil/data_types.go
DeepCopy
func (ui UserInfo) DeepCopy() UserInfo { copyUI := ui copyUI.VerifyingKeys = make( []kbfscrypto.VerifyingKey, len(ui.VerifyingKeys)) copy(copyUI.VerifyingKeys, ui.VerifyingKeys) copyUI.CryptPublicKeys = make( []kbfscrypto.CryptPublicKey, len(ui.CryptPublicKeys)) copy(copyUI.CryptPublicKeys, ui.CryptPublicKeys) copyUI.KIDNames = make(map[keybase1.KID]string, len(ui.KIDNames)) for k, v := range ui.KIDNames { copyUI.KIDNames[k] = v } copyUI.RevokedVerifyingKeys = make( map[kbfscrypto.VerifyingKey]RevokedKeyInfo, len(ui.RevokedVerifyingKeys)) for k, v := range ui.RevokedVerifyingKeys { copyUI.RevokedVerifyingKeys[k] = v } copyUI.RevokedCryptPublicKeys = make( map[kbfscrypto.CryptPublicKey]RevokedKeyInfo, len(ui.RevokedCryptPublicKeys)) for k, v := range ui.RevokedCryptPublicKeys { copyUI.RevokedCryptPublicKeys[k] = v } return copyUI }
go
func (ui UserInfo) DeepCopy() UserInfo { copyUI := ui copyUI.VerifyingKeys = make( []kbfscrypto.VerifyingKey, len(ui.VerifyingKeys)) copy(copyUI.VerifyingKeys, ui.VerifyingKeys) copyUI.CryptPublicKeys = make( []kbfscrypto.CryptPublicKey, len(ui.CryptPublicKeys)) copy(copyUI.CryptPublicKeys, ui.CryptPublicKeys) copyUI.KIDNames = make(map[keybase1.KID]string, len(ui.KIDNames)) for k, v := range ui.KIDNames { copyUI.KIDNames[k] = v } copyUI.RevokedVerifyingKeys = make( map[kbfscrypto.VerifyingKey]RevokedKeyInfo, len(ui.RevokedVerifyingKeys)) for k, v := range ui.RevokedVerifyingKeys { copyUI.RevokedVerifyingKeys[k] = v } copyUI.RevokedCryptPublicKeys = make( map[kbfscrypto.CryptPublicKey]RevokedKeyInfo, len(ui.RevokedCryptPublicKeys)) for k, v := range ui.RevokedCryptPublicKeys { copyUI.RevokedCryptPublicKeys[k] = v } return copyUI }
[ "func", "(", "ui", "UserInfo", ")", "DeepCopy", "(", ")", "UserInfo", "{", "copyUI", ":=", "ui", "\n", "copyUI", ".", "VerifyingKeys", "=", "make", "(", "[", "]", "kbfscrypto", ".", "VerifyingKey", ",", "len", "(", "ui", ".", "VerifyingKeys", ")", ")", "\n", "copy", "(", "copyUI", ".", "VerifyingKeys", ",", "ui", ".", "VerifyingKeys", ")", "\n", "copyUI", ".", "CryptPublicKeys", "=", "make", "(", "[", "]", "kbfscrypto", ".", "CryptPublicKey", ",", "len", "(", "ui", ".", "CryptPublicKeys", ")", ")", "\n", "copy", "(", "copyUI", ".", "CryptPublicKeys", ",", "ui", ".", "CryptPublicKeys", ")", "\n", "copyUI", ".", "KIDNames", "=", "make", "(", "map", "[", "keybase1", ".", "KID", "]", "string", ",", "len", "(", "ui", ".", "KIDNames", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "ui", ".", "KIDNames", "{", "copyUI", ".", "KIDNames", "[", "k", "]", "=", "v", "\n", "}", "\n", "copyUI", ".", "RevokedVerifyingKeys", "=", "make", "(", "map", "[", "kbfscrypto", ".", "VerifyingKey", "]", "RevokedKeyInfo", ",", "len", "(", "ui", ".", "RevokedVerifyingKeys", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "ui", ".", "RevokedVerifyingKeys", "{", "copyUI", ".", "RevokedVerifyingKeys", "[", "k", "]", "=", "v", "\n", "}", "\n", "copyUI", ".", "RevokedCryptPublicKeys", "=", "make", "(", "map", "[", "kbfscrypto", ".", "CryptPublicKey", "]", "RevokedKeyInfo", ",", "len", "(", "ui", ".", "RevokedCryptPublicKeys", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "ui", ".", "RevokedCryptPublicKeys", "{", "copyUI", ".", "RevokedCryptPublicKeys", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "copyUI", "\n", "}" ]
// DeepCopy returns a copy of `ui`, including deep copies of all slice // and map members.
[ "DeepCopy", "returns", "a", "copy", "of", "ui", "including", "deep", "copies", "of", "all", "slice", "and", "map", "members", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/idutil/data_types.go#L89-L114
161,370
keybase/client
go/kbfs/libfs/error_file.go
GetEncodedErrors
func GetEncodedErrors(config libkbfs.Config) func(context.Context) ([]byte, time.Time, error) { return func(_ context.Context) ([]byte, time.Time, error) { errors := config.Reporter().AllKnownErrors() jsonErrors := make([]JSONReportedError, len(errors)) for i, e := range errors { jsonErrors[i].Time = e.Time jsonErrors[i].Error = e.Error.Error() jsonErrors[i].Stack = convertStack(e.Stack) } data, err := PrettyJSON(jsonErrors) var t time.Time if len(errors) > 0 { t = errors[len(errors)-1].Time } return data, t, err } }
go
func GetEncodedErrors(config libkbfs.Config) func(context.Context) ([]byte, time.Time, error) { return func(_ context.Context) ([]byte, time.Time, error) { errors := config.Reporter().AllKnownErrors() jsonErrors := make([]JSONReportedError, len(errors)) for i, e := range errors { jsonErrors[i].Time = e.Time jsonErrors[i].Error = e.Error.Error() jsonErrors[i].Stack = convertStack(e.Stack) } data, err := PrettyJSON(jsonErrors) var t time.Time if len(errors) > 0 { t = errors[len(errors)-1].Time } return data, t, err } }
[ "func", "GetEncodedErrors", "(", "config", "libkbfs", ".", "Config", ")", "func", "(", "context", ".", "Context", ")", "(", "[", "]", "byte", ",", "time", ".", "Time", ",", "error", ")", "{", "return", "func", "(", "_", "context", ".", "Context", ")", "(", "[", "]", "byte", ",", "time", ".", "Time", ",", "error", ")", "{", "errors", ":=", "config", ".", "Reporter", "(", ")", ".", "AllKnownErrors", "(", ")", "\n", "jsonErrors", ":=", "make", "(", "[", "]", "JSONReportedError", ",", "len", "(", "errors", ")", ")", "\n", "for", "i", ",", "e", ":=", "range", "errors", "{", "jsonErrors", "[", "i", "]", ".", "Time", "=", "e", ".", "Time", "\n", "jsonErrors", "[", "i", "]", ".", "Error", "=", "e", ".", "Error", ".", "Error", "(", ")", "\n", "jsonErrors", "[", "i", "]", ".", "Stack", "=", "convertStack", "(", "e", ".", "Stack", ")", "\n", "}", "\n", "data", ",", "err", ":=", "PrettyJSON", "(", "jsonErrors", ")", "\n", "var", "t", "time", ".", "Time", "\n", "if", "len", "(", "errors", ")", ">", "0", "{", "t", "=", "errors", "[", "len", "(", "errors", ")", "-", "1", "]", ".", "Time", "\n", "}", "\n", "return", "data", ",", "t", ",", "err", "\n", "}", "\n", "}" ]
// GetEncodedErrors gets the list of encoded errors in a format suitable // for error file.
[ "GetEncodedErrors", "gets", "the", "list", "of", "encoded", "errors", "in", "a", "format", "suitable", "for", "error", "file", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfs/error_file.go#L34-L50
161,371
keybase/client
go/mounter/mounter_osx.go
cstr
func cstr(ca []int8) string { s := make([]byte, 0, len(ca)) for _, c := range ca { if c == 0x00 { break } s = append(s, byte(c)) } return string(s) }
go
func cstr(ca []int8) string { s := make([]byte, 0, len(ca)) for _, c := range ca { if c == 0x00 { break } s = append(s, byte(c)) } return string(s) }
[ "func", "cstr", "(", "ca", "[", "]", "int8", ")", "string", "{", "s", ":=", "make", "(", "[", "]", "byte", ",", "0", ",", "len", "(", "ca", ")", ")", "\n", "for", "_", ",", "c", ":=", "range", "ca", "{", "if", "c", "==", "0x00", "{", "break", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "byte", "(", "c", ")", ")", "\n", "}", "\n", "return", "string", "(", "s", ")", "\n", "}" ]
// cstr converts a nil-terminated C string into a Go string
[ "cstr", "converts", "a", "nil", "-", "terminated", "C", "string", "into", "a", "Go", "string" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/mounter/mounter_osx.go#L42-L51
161,372
keybase/client
go/chat/storage/storage.go
Merge
func (s *Storage) Merge(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, msgs []chat1.MessageUnboxed) (res MergeResult, err Error) { defer s.Trace(ctx, func() error { return err }, "Merge")() return s.MergeHelper(ctx, convID, uid, msgs, nil) }
go
func (s *Storage) Merge(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, msgs []chat1.MessageUnboxed) (res MergeResult, err Error) { defer s.Trace(ctx, func() error { return err }, "Merge")() return s.MergeHelper(ctx, convID, uid, msgs, nil) }
[ "func", "(", "s", "*", "Storage", ")", "Merge", "(", "ctx", "context", ".", "Context", ",", "convID", "chat1", ".", "ConversationID", ",", "uid", "gregor1", ".", "UID", ",", "msgs", "[", "]", "chat1", ".", "MessageUnboxed", ")", "(", "res", "MergeResult", ",", "err", "Error", ")", "{", "defer", "s", ".", "Trace", "(", "ctx", ",", "func", "(", ")", "error", "{", "return", "err", "}", ",", "\"", "\"", ")", "(", ")", "\n", "return", "s", ".", "MergeHelper", "(", "ctx", ",", "convID", ",", "uid", ",", "msgs", ",", "nil", ")", "\n", "}" ]
// Merge requires msgs to be sorted by descending message ID
[ "Merge", "requires", "msgs", "to", "be", "sorted", "by", "descending", "message", "ID" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L378-L382
161,373
keybase/client
go/chat/storage/storage.go
applyExpunge
func (s *Storage) applyExpunge(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, expunge chat1.Expunge) (*chat1.Expunge, Error) { s.Debug(ctx, "applyExpunge(%v, %v, %v)", convID, uid, expunge.Upto) de := func(format string, args ...interface{}) { s.Debug(ctx, "applyExpunge: "+fmt.Sprintf(format, args...)) } rc := NewInsatiableResultCollector() // collect all messages err := s.engine.ReadMessages(ctx, rc, convID, uid, expunge.Upto-1, 0) switch err.(type) { case nil: // ok case MissError: de("record-only delh: no local messages") err := s.delhTracker.setMaxDeleteHistoryUpto(ctx, convID, uid, expunge.Upto) if err != nil { de("failed to store delh track: %v", err) } return nil, nil default: return nil, err } var allAssets []chat1.Asset var writeback, allPurged []chat1.MessageUnboxed for _, msg := range rc.Result() { if !chat1.IsDeletableByDeleteHistory(msg.GetMessageType()) { // Skip message types that cannot be deleted this way continue } if !msg.IsValid() { de("skipping invalid msg: %v", msg.DebugString()) continue } mvalid := msg.Valid() if mvalid.MessageBody.IsNil() { continue } mvalid.ServerHeader.SupersededBy = expunge.Basis // Can be 0 msgPurged, assets := s.purgeMessage(mvalid) allPurged = append(allPurged, msg) allAssets = append(allAssets, assets...) writeback = append(writeback, msgPurged) } // queue asset deletions in the background s.assetDeleter.DeleteAssets(ctx, uid, convID, allAssets) // queue search index update in the background go s.G().Indexer.Remove(ctx, convID, uid, allPurged) de("deleting %v messages", len(writeback)) if err = s.engine.WriteMessages(ctx, convID, uid, writeback); err != nil { de("write messages failed: %v", err) return nil, err } err = s.delhTracker.setDeletedUpto(ctx, convID, uid, expunge.Upto) if err != nil { de("failed to store delh track: %v", err) } return &expunge, nil }
go
func (s *Storage) applyExpunge(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, expunge chat1.Expunge) (*chat1.Expunge, Error) { s.Debug(ctx, "applyExpunge(%v, %v, %v)", convID, uid, expunge.Upto) de := func(format string, args ...interface{}) { s.Debug(ctx, "applyExpunge: "+fmt.Sprintf(format, args...)) } rc := NewInsatiableResultCollector() // collect all messages err := s.engine.ReadMessages(ctx, rc, convID, uid, expunge.Upto-1, 0) switch err.(type) { case nil: // ok case MissError: de("record-only delh: no local messages") err := s.delhTracker.setMaxDeleteHistoryUpto(ctx, convID, uid, expunge.Upto) if err != nil { de("failed to store delh track: %v", err) } return nil, nil default: return nil, err } var allAssets []chat1.Asset var writeback, allPurged []chat1.MessageUnboxed for _, msg := range rc.Result() { if !chat1.IsDeletableByDeleteHistory(msg.GetMessageType()) { // Skip message types that cannot be deleted this way continue } if !msg.IsValid() { de("skipping invalid msg: %v", msg.DebugString()) continue } mvalid := msg.Valid() if mvalid.MessageBody.IsNil() { continue } mvalid.ServerHeader.SupersededBy = expunge.Basis // Can be 0 msgPurged, assets := s.purgeMessage(mvalid) allPurged = append(allPurged, msg) allAssets = append(allAssets, assets...) writeback = append(writeback, msgPurged) } // queue asset deletions in the background s.assetDeleter.DeleteAssets(ctx, uid, convID, allAssets) // queue search index update in the background go s.G().Indexer.Remove(ctx, convID, uid, allPurged) de("deleting %v messages", len(writeback)) if err = s.engine.WriteMessages(ctx, convID, uid, writeback); err != nil { de("write messages failed: %v", err) return nil, err } err = s.delhTracker.setDeletedUpto(ctx, convID, uid, expunge.Upto) if err != nil { de("failed to store delh track: %v", err) } return &expunge, nil }
[ "func", "(", "s", "*", "Storage", ")", "applyExpunge", "(", "ctx", "context", ".", "Context", ",", "convID", "chat1", ".", "ConversationID", ",", "uid", "gregor1", ".", "UID", ",", "expunge", "chat1", ".", "Expunge", ")", "(", "*", "chat1", ".", "Expunge", ",", "Error", ")", "{", "s", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "convID", ",", "uid", ",", "expunge", ".", "Upto", ")", "\n\n", "de", ":=", "func", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "s", ".", "Debug", "(", "ctx", ",", "\"", "\"", "+", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ")", "\n", "}", "\n\n", "rc", ":=", "NewInsatiableResultCollector", "(", ")", "// collect all messages", "\n", "err", ":=", "s", ".", "engine", ".", "ReadMessages", "(", "ctx", ",", "rc", ",", "convID", ",", "uid", ",", "expunge", ".", "Upto", "-", "1", ",", "0", ")", "\n", "switch", "err", ".", "(", "type", ")", "{", "case", "nil", ":", "// ok", "case", "MissError", ":", "de", "(", "\"", "\"", ")", "\n", "err", ":=", "s", ".", "delhTracker", ".", "setMaxDeleteHistoryUpto", "(", "ctx", ",", "convID", ",", "uid", ",", "expunge", ".", "Upto", ")", "\n", "if", "err", "!=", "nil", "{", "de", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "default", ":", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "allAssets", "[", "]", "chat1", ".", "Asset", "\n", "var", "writeback", ",", "allPurged", "[", "]", "chat1", ".", "MessageUnboxed", "\n", "for", "_", ",", "msg", ":=", "range", "rc", ".", "Result", "(", ")", "{", "if", "!", "chat1", ".", "IsDeletableByDeleteHistory", "(", "msg", ".", "GetMessageType", "(", ")", ")", "{", "// Skip message types that cannot be deleted this way", "continue", "\n", "}", "\n", "if", "!", "msg", ".", "IsValid", "(", ")", "{", "de", "(", "\"", "\"", ",", "msg", ".", "DebugString", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "mvalid", ":=", "msg", ".", "Valid", "(", ")", "\n", "if", "mvalid", ".", "MessageBody", ".", "IsNil", "(", ")", "{", "continue", "\n", "}", "\n", "mvalid", ".", "ServerHeader", ".", "SupersededBy", "=", "expunge", ".", "Basis", "// Can be 0", "\n", "msgPurged", ",", "assets", ":=", "s", ".", "purgeMessage", "(", "mvalid", ")", "\n", "allPurged", "=", "append", "(", "allPurged", ",", "msg", ")", "\n", "allAssets", "=", "append", "(", "allAssets", ",", "assets", "...", ")", "\n", "writeback", "=", "append", "(", "writeback", ",", "msgPurged", ")", "\n", "}", "\n\n", "// queue asset deletions in the background", "s", ".", "assetDeleter", ".", "DeleteAssets", "(", "ctx", ",", "uid", ",", "convID", ",", "allAssets", ")", "\n", "// queue search index update in the background", "go", "s", ".", "G", "(", ")", ".", "Indexer", ".", "Remove", "(", "ctx", ",", "convID", ",", "uid", ",", "allPurged", ")", "\n\n", "de", "(", "\"", "\"", ",", "len", "(", "writeback", ")", ")", "\n", "if", "err", "=", "s", ".", "engine", ".", "WriteMessages", "(", "ctx", ",", "convID", ",", "uid", ",", "writeback", ")", ";", "err", "!=", "nil", "{", "de", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "s", ".", "delhTracker", ".", "setDeletedUpto", "(", "ctx", ",", "convID", ",", "uid", ",", "expunge", ".", "Upto", ")", "\n", "if", "err", "!=", "nil", "{", "de", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "expunge", ",", "nil", "\n", "}" ]
// Apply a delete history. // Returns a non-nil expunge if deletes happened. // Always runs through local messages.
[ "Apply", "a", "delete", "history", ".", "Returns", "a", "non", "-", "nil", "expunge", "if", "deletes", "happened", ".", "Always", "runs", "through", "local", "messages", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L760-L824
161,374
keybase/client
go/chat/storage/storage.go
clearUpthrough
func (s *Storage) clearUpthrough(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, upthrough chat1.MessageID) (err Error) { defer s.Trace(ctx, func() error { return err }, "clearUpthrough")() key, ierr := GetSecretBoxKey(ctx, s.G().ExternalG(), DefaultSecretUI) if ierr != nil { return MiscError{Msg: "unable to get secret key: " + ierr.Error()} } ctx, err = s.engine.Init(ctx, key, convID, uid) if err != nil { return err } var msgIDs []chat1.MessageID for m := upthrough; m > 0; m-- { msgIDs = append(msgIDs, m) } return s.engine.ClearMessages(ctx, convID, uid, msgIDs) }
go
func (s *Storage) clearUpthrough(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, upthrough chat1.MessageID) (err Error) { defer s.Trace(ctx, func() error { return err }, "clearUpthrough")() key, ierr := GetSecretBoxKey(ctx, s.G().ExternalG(), DefaultSecretUI) if ierr != nil { return MiscError{Msg: "unable to get secret key: " + ierr.Error()} } ctx, err = s.engine.Init(ctx, key, convID, uid) if err != nil { return err } var msgIDs []chat1.MessageID for m := upthrough; m > 0; m-- { msgIDs = append(msgIDs, m) } return s.engine.ClearMessages(ctx, convID, uid, msgIDs) }
[ "func", "(", "s", "*", "Storage", ")", "clearUpthrough", "(", "ctx", "context", ".", "Context", ",", "convID", "chat1", ".", "ConversationID", ",", "uid", "gregor1", ".", "UID", ",", "upthrough", "chat1", ".", "MessageID", ")", "(", "err", "Error", ")", "{", "defer", "s", ".", "Trace", "(", "ctx", ",", "func", "(", ")", "error", "{", "return", "err", "}", ",", "\"", "\"", ")", "(", ")", "\n", "key", ",", "ierr", ":=", "GetSecretBoxKey", "(", "ctx", ",", "s", ".", "G", "(", ")", ".", "ExternalG", "(", ")", ",", "DefaultSecretUI", ")", "\n", "if", "ierr", "!=", "nil", "{", "return", "MiscError", "{", "Msg", ":", "\"", "\"", "+", "ierr", ".", "Error", "(", ")", "}", "\n", "}", "\n", "ctx", ",", "err", "=", "s", ".", "engine", ".", "Init", "(", "ctx", ",", "key", ",", "convID", ",", "uid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "msgIDs", "[", "]", "chat1", ".", "MessageID", "\n", "for", "m", ":=", "upthrough", ";", "m", ">", "0", ";", "m", "--", "{", "msgIDs", "=", "append", "(", "msgIDs", ",", "m", ")", "\n", "}", "\n", "return", "s", ".", "engine", ".", "ClearMessages", "(", "ctx", ",", "convID", ",", "uid", ",", "msgIDs", ")", "\n", "}" ]
// clearUpthrough clears up to the given message ID, inclusive
[ "clearUpthrough", "clears", "up", "to", "the", "given", "message", "ID", "inclusive" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L827-L844
161,375
keybase/client
go/chat/storage/storage.go
updateReactionIDs
func (s *Storage) updateReactionIDs(reactionIDs []chat1.MessageID, msgid chat1.MessageID) ([]chat1.MessageID, bool) { for _, reactionID := range reactionIDs { if reactionID == msgid { return reactionIDs, false } } return append(reactionIDs, msgid), true }
go
func (s *Storage) updateReactionIDs(reactionIDs []chat1.MessageID, msgid chat1.MessageID) ([]chat1.MessageID, bool) { for _, reactionID := range reactionIDs { if reactionID == msgid { return reactionIDs, false } } return append(reactionIDs, msgid), true }
[ "func", "(", "s", "*", "Storage", ")", "updateReactionIDs", "(", "reactionIDs", "[", "]", "chat1", ".", "MessageID", ",", "msgid", "chat1", ".", "MessageID", ")", "(", "[", "]", "chat1", ".", "MessageID", ",", "bool", ")", "{", "for", "_", ",", "reactionID", ":=", "range", "reactionIDs", "{", "if", "reactionID", "==", "msgid", "{", "return", "reactionIDs", ",", "false", "\n", "}", "\n", "}", "\n", "return", "append", "(", "reactionIDs", ",", "msgid", ")", ",", "true", "\n", "}" ]
// updateReactionIDs appends `msgid` to `reactionIDs` if it is not already // present.
[ "updateReactionIDs", "appends", "msgid", "to", "reactionIDs", "if", "it", "is", "not", "already", "present", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L1184-L1191
161,376
keybase/client
go/chat/storage/storage.go
updateReactionTargetOnDelete
func (s *Storage) updateReactionTargetOnDelete(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, reactionMsg *chat1.MessageUnboxed) (*chat1.MessageUnboxed, bool, Error) { s.Debug(ctx, "updateReactionTargetOnDelete: reationMsg: %v", reactionMsg) if reactionMsg.Valid().MessageBody.IsNil() { return nil, false, nil } targetMsgID := reactionMsg.Valid().MessageBody.Reaction().MessageID targetMsg, err := s.getMessage(ctx, convID, uid, targetMsgID) if err != nil || targetMsg == nil { return nil, false, err } if targetMsg.IsValid() { mvalid := targetMsg.Valid() reactionIDs := []chat1.MessageID{} for _, msgID := range mvalid.ServerHeader.ReactionIDs { if msgID != reactionMsg.GetMessageID() { reactionIDs = append(reactionIDs, msgID) } } updated := len(mvalid.ServerHeader.ReactionIDs) != len(reactionIDs) mvalid.ServerHeader.ReactionIDs = reactionIDs newMsg := chat1.NewMessageUnboxedWithValid(mvalid) return &newMsg, updated, nil } return nil, false, nil }
go
func (s *Storage) updateReactionTargetOnDelete(ctx context.Context, convID chat1.ConversationID, uid gregor1.UID, reactionMsg *chat1.MessageUnboxed) (*chat1.MessageUnboxed, bool, Error) { s.Debug(ctx, "updateReactionTargetOnDelete: reationMsg: %v", reactionMsg) if reactionMsg.Valid().MessageBody.IsNil() { return nil, false, nil } targetMsgID := reactionMsg.Valid().MessageBody.Reaction().MessageID targetMsg, err := s.getMessage(ctx, convID, uid, targetMsgID) if err != nil || targetMsg == nil { return nil, false, err } if targetMsg.IsValid() { mvalid := targetMsg.Valid() reactionIDs := []chat1.MessageID{} for _, msgID := range mvalid.ServerHeader.ReactionIDs { if msgID != reactionMsg.GetMessageID() { reactionIDs = append(reactionIDs, msgID) } } updated := len(mvalid.ServerHeader.ReactionIDs) != len(reactionIDs) mvalid.ServerHeader.ReactionIDs = reactionIDs newMsg := chat1.NewMessageUnboxedWithValid(mvalid) return &newMsg, updated, nil } return nil, false, nil }
[ "func", "(", "s", "*", "Storage", ")", "updateReactionTargetOnDelete", "(", "ctx", "context", ".", "Context", ",", "convID", "chat1", ".", "ConversationID", ",", "uid", "gregor1", ".", "UID", ",", "reactionMsg", "*", "chat1", ".", "MessageUnboxed", ")", "(", "*", "chat1", ".", "MessageUnboxed", ",", "bool", ",", "Error", ")", "{", "s", ".", "Debug", "(", "ctx", ",", "\"", "\"", ",", "reactionMsg", ")", "\n\n", "if", "reactionMsg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "false", ",", "nil", "\n", "}", "\n\n", "targetMsgID", ":=", "reactionMsg", ".", "Valid", "(", ")", ".", "MessageBody", ".", "Reaction", "(", ")", ".", "MessageID", "\n", "targetMsg", ",", "err", ":=", "s", ".", "getMessage", "(", "ctx", ",", "convID", ",", "uid", ",", "targetMsgID", ")", "\n", "if", "err", "!=", "nil", "||", "targetMsg", "==", "nil", "{", "return", "nil", ",", "false", ",", "err", "\n", "}", "\n", "if", "targetMsg", ".", "IsValid", "(", ")", "{", "mvalid", ":=", "targetMsg", ".", "Valid", "(", ")", "\n", "reactionIDs", ":=", "[", "]", "chat1", ".", "MessageID", "{", "}", "\n", "for", "_", ",", "msgID", ":=", "range", "mvalid", ".", "ServerHeader", ".", "ReactionIDs", "{", "if", "msgID", "!=", "reactionMsg", ".", "GetMessageID", "(", ")", "{", "reactionIDs", "=", "append", "(", "reactionIDs", ",", "msgID", ")", "\n", "}", "\n", "}", "\n", "updated", ":=", "len", "(", "mvalid", ".", "ServerHeader", ".", "ReactionIDs", ")", "!=", "len", "(", "reactionIDs", ")", "\n", "mvalid", ".", "ServerHeader", ".", "ReactionIDs", "=", "reactionIDs", "\n", "newMsg", ":=", "chat1", ".", "NewMessageUnboxedWithValid", "(", "mvalid", ")", "\n", "return", "&", "newMsg", ",", "updated", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "false", ",", "nil", "\n", "}" ]
// updateReactionTargetOnDelete modifies the reaction's target message when the // reaction itself is deleted
[ "updateReactionTargetOnDelete", "modifies", "the", "reaction", "s", "target", "message", "when", "the", "reaction", "itself", "is", "deleted" ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L1195-L1222
161,377
keybase/client
go/chat/storage/storage.go
purgeMessage
func (s *Storage) purgeMessage(mvalid chat1.MessageUnboxedValid) (chat1.MessageUnboxed, []chat1.Asset) { assets := utils.AssetsForMessage(s.G(), mvalid.MessageBody) var emptyBody chat1.MessageBody mvalid.MessageBody = emptyBody var emptyReactions chat1.ReactionMap mvalid.Reactions = emptyReactions return chat1.NewMessageUnboxedWithValid(mvalid), assets }
go
func (s *Storage) purgeMessage(mvalid chat1.MessageUnboxedValid) (chat1.MessageUnboxed, []chat1.Asset) { assets := utils.AssetsForMessage(s.G(), mvalid.MessageBody) var emptyBody chat1.MessageBody mvalid.MessageBody = emptyBody var emptyReactions chat1.ReactionMap mvalid.Reactions = emptyReactions return chat1.NewMessageUnboxedWithValid(mvalid), assets }
[ "func", "(", "s", "*", "Storage", ")", "purgeMessage", "(", "mvalid", "chat1", ".", "MessageUnboxedValid", ")", "(", "chat1", ".", "MessageUnboxed", ",", "[", "]", "chat1", ".", "Asset", ")", "{", "assets", ":=", "utils", ".", "AssetsForMessage", "(", "s", ".", "G", "(", ")", ",", "mvalid", ".", "MessageBody", ")", "\n", "var", "emptyBody", "chat1", ".", "MessageBody", "\n", "mvalid", ".", "MessageBody", "=", "emptyBody", "\n", "var", "emptyReactions", "chat1", ".", "ReactionMap", "\n", "mvalid", ".", "Reactions", "=", "emptyReactions", "\n", "return", "chat1", ".", "NewMessageUnboxedWithValid", "(", "mvalid", ")", ",", "assets", "\n", "}" ]
// Clears the body of a message and returns any assets to be deleted.
[ "Clears", "the", "body", "of", "a", "message", "and", "returns", "any", "assets", "to", "be", "deleted", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/chat/storage/storage.go#L1225-L1232
161,378
keybase/client
go/kbfs/libkbfs/ops.go
AddRefBlock
func (oc *OpCommon) AddRefBlock(ptr data.BlockPointer) { oc.RefBlocks = append(oc.RefBlocks, ptr) }
go
func (oc *OpCommon) AddRefBlock(ptr data.BlockPointer) { oc.RefBlocks = append(oc.RefBlocks, ptr) }
[ "func", "(", "oc", "*", "OpCommon", ")", "AddRefBlock", "(", "ptr", "data", ".", "BlockPointer", ")", "{", "oc", ".", "RefBlocks", "=", "append", "(", "oc", ".", "RefBlocks", ",", "ptr", ")", "\n", "}" ]
// AddRefBlock adds this block to the list of newly-referenced blocks // for this op.
[ "AddRefBlock", "adds", "this", "block", "to", "the", "list", "of", "newly", "-", "referenced", "blocks", "for", "this", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L195-L197
161,379
keybase/client
go/kbfs/libkbfs/ops.go
DelRefBlock
func (oc *OpCommon) DelRefBlock(ptr data.BlockPointer) { for i, ref := range oc.RefBlocks { if ptr == ref { oc.RefBlocks = append(oc.RefBlocks[:i], oc.RefBlocks[i+1:]...) break } } }
go
func (oc *OpCommon) DelRefBlock(ptr data.BlockPointer) { for i, ref := range oc.RefBlocks { if ptr == ref { oc.RefBlocks = append(oc.RefBlocks[:i], oc.RefBlocks[i+1:]...) break } } }
[ "func", "(", "oc", "*", "OpCommon", ")", "DelRefBlock", "(", "ptr", "data", ".", "BlockPointer", ")", "{", "for", "i", ",", "ref", ":=", "range", "oc", ".", "RefBlocks", "{", "if", "ptr", "==", "ref", "{", "oc", ".", "RefBlocks", "=", "append", "(", "oc", ".", "RefBlocks", "[", ":", "i", "]", ",", "oc", ".", "RefBlocks", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// DelRefBlock removes the first reference of the given block from the // list of newly-referenced blocks for this op.
[ "DelRefBlock", "removes", "the", "first", "reference", "of", "the", "given", "block", "from", "the", "list", "of", "newly", "-", "referenced", "blocks", "for", "this", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L201-L208
161,380
keybase/client
go/kbfs/libkbfs/ops.go
AddUnrefBlock
func (oc *OpCommon) AddUnrefBlock(ptr data.BlockPointer) { oc.UnrefBlocks = append(oc.UnrefBlocks, ptr) }
go
func (oc *OpCommon) AddUnrefBlock(ptr data.BlockPointer) { oc.UnrefBlocks = append(oc.UnrefBlocks, ptr) }
[ "func", "(", "oc", "*", "OpCommon", ")", "AddUnrefBlock", "(", "ptr", "data", ".", "BlockPointer", ")", "{", "oc", ".", "UnrefBlocks", "=", "append", "(", "oc", ".", "UnrefBlocks", ",", "ptr", ")", "\n", "}" ]
// AddUnrefBlock adds this block to the list of newly-unreferenced blocks // for this op.
[ "AddUnrefBlock", "adds", "this", "block", "to", "the", "list", "of", "newly", "-", "unreferenced", "blocks", "for", "this", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L212-L214
161,381
keybase/client
go/kbfs/libkbfs/ops.go
DelUnrefBlock
func (oc *OpCommon) DelUnrefBlock(ptr data.BlockPointer) { for i, unref := range oc.UnrefBlocks { if ptr == unref { oc.UnrefBlocks = append(oc.UnrefBlocks[:i], oc.UnrefBlocks[i+1:]...) break } } }
go
func (oc *OpCommon) DelUnrefBlock(ptr data.BlockPointer) { for i, unref := range oc.UnrefBlocks { if ptr == unref { oc.UnrefBlocks = append(oc.UnrefBlocks[:i], oc.UnrefBlocks[i+1:]...) break } } }
[ "func", "(", "oc", "*", "OpCommon", ")", "DelUnrefBlock", "(", "ptr", "data", ".", "BlockPointer", ")", "{", "for", "i", ",", "unref", ":=", "range", "oc", ".", "UnrefBlocks", "{", "if", "ptr", "==", "unref", "{", "oc", ".", "UnrefBlocks", "=", "append", "(", "oc", ".", "UnrefBlocks", "[", ":", "i", "]", ",", "oc", ".", "UnrefBlocks", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}" ]
// DelUnrefBlock removes the first unreference of the given block from // the list of unreferenced blocks for this op.
[ "DelUnrefBlock", "removes", "the", "first", "unreference", "of", "the", "given", "block", "from", "the", "list", "of", "unreferenced", "blocks", "for", "this", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L218-L225
161,382
keybase/client
go/kbfs/libkbfs/ops.go
AddUpdate
func (oc *OpCommon) AddUpdate(oldPtr data.BlockPointer, newPtr data.BlockPointer) { // Either pointer may be zero, if we're building an op that // will be fixed up later. bu := blockUpdate{oldPtr, newPtr} oc.Updates = append(oc.Updates, bu) }
go
func (oc *OpCommon) AddUpdate(oldPtr data.BlockPointer, newPtr data.BlockPointer) { // Either pointer may be zero, if we're building an op that // will be fixed up later. bu := blockUpdate{oldPtr, newPtr} oc.Updates = append(oc.Updates, bu) }
[ "func", "(", "oc", "*", "OpCommon", ")", "AddUpdate", "(", "oldPtr", "data", ".", "BlockPointer", ",", "newPtr", "data", ".", "BlockPointer", ")", "{", "// Either pointer may be zero, if we're building an op that", "// will be fixed up later.", "bu", ":=", "blockUpdate", "{", "oldPtr", ",", "newPtr", "}", "\n", "oc", ".", "Updates", "=", "append", "(", "oc", ".", "Updates", ",", "bu", ")", "\n", "}" ]
// AddUpdate adds a mapping from an old block to the new version of // that block, for this op.
[ "AddUpdate", "adds", "a", "mapping", "from", "an", "old", "block", "to", "the", "new", "version", "of", "that", "block", "for", "this", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L229-L234
161,383
keybase/client
go/kbfs/libkbfs/ops.go
ToEditNotification
func (oc *OpCommon) ToEditNotification( _ kbfsmd.Revision, _ time.Time, _ kbfscrypto.VerifyingKey, _ keybase1.UID, _ tlf.ID) *kbfsedits.NotificationMessage { // Ops embedding this that can be converted should override this. return nil }
go
func (oc *OpCommon) ToEditNotification( _ kbfsmd.Revision, _ time.Time, _ kbfscrypto.VerifyingKey, _ keybase1.UID, _ tlf.ID) *kbfsedits.NotificationMessage { // Ops embedding this that can be converted should override this. return nil }
[ "func", "(", "oc", "*", "OpCommon", ")", "ToEditNotification", "(", "_", "kbfsmd", ".", "Revision", ",", "_", "time", ".", "Time", ",", "_", "kbfscrypto", ".", "VerifyingKey", ",", "_", "keybase1", ".", "UID", ",", "_", "tlf", ".", "ID", ")", "*", "kbfsedits", ".", "NotificationMessage", "{", "// Ops embedding this that can be converted should override this.", "return", "nil", "\n", "}" ]
// ToEditNotification implements the op interface for OpCommon.
[ "ToEditNotification", "implements", "the", "op", "interface", "for", "OpCommon", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L305-L310
161,384
keybase/client
go/kbfs/libkbfs/ops.go
End
func (w WriteRange) End() uint64 { if w.isTruncate() { panic("Truncates don't have an end") } return w.Off + w.Len }
go
func (w WriteRange) End() uint64 { if w.isTruncate() { panic("Truncates don't have an end") } return w.Off + w.Len }
[ "func", "(", "w", "WriteRange", ")", "End", "(", ")", "uint64", "{", "if", "w", ".", "isTruncate", "(", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "w", ".", "Off", "+", "w", ".", "Len", "\n", "}" ]
// End returns the index of the largest byte not affected by this // write. It only makes sense to call this for non-truncates.
[ "End", "returns", "the", "index", "of", "the", "largest", "byte", "not", "affected", "by", "this", "write", ".", "It", "only", "makes", "sense", "to", "call", "this", "for", "non", "-", "truncates", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L810-L815
161,385
keybase/client
go/kbfs/libkbfs/ops.go
SizeExceptUpdates
func (gco *GCOp) SizeExceptUpdates() uint64 { return data.BPSize * uint64(len(gco.UnrefBlocks)) }
go
func (gco *GCOp) SizeExceptUpdates() uint64 { return data.BPSize * uint64(len(gco.UnrefBlocks)) }
[ "func", "(", "gco", "*", "GCOp", ")", "SizeExceptUpdates", "(", ")", "uint64", "{", "return", "data", ".", "BPSize", "*", "uint64", "(", "len", "(", "gco", ".", "UnrefBlocks", ")", ")", "\n", "}" ]
// SizeExceptUpdates implements op.
[ "SizeExceptUpdates", "implements", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L1432-L1434
161,386
keybase/client
go/kbfs/libkbfs/ops.go
StringWithRefs
func (gco *GCOp) StringWithRefs(indent string) string { res := gco.String() + "\n" res += gco.stringWithRefs(indent) return res }
go
func (gco *GCOp) StringWithRefs(indent string) string { res := gco.String() + "\n" res += gco.stringWithRefs(indent) return res }
[ "func", "(", "gco", "*", "GCOp", ")", "StringWithRefs", "(", "indent", "string", ")", "string", "{", "res", ":=", "gco", ".", "String", "(", ")", "+", "\"", "\\n", "\"", "\n", "res", "+=", "gco", ".", "stringWithRefs", "(", "indent", ")", "\n", "return", "res", "\n", "}" ]
// StringWithRefs implements the op interface for GCOp.
[ "StringWithRefs", "implements", "the", "op", "interface", "for", "GCOp", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L1449-L1453
161,387
keybase/client
go/kbfs/libkbfs/ops.go
checkConflict
func (gco *GCOp) checkConflict( ctx context.Context, renamer ConflictRenamer, mergedOp op, isFile bool) (crAction, error) { return nil, nil }
go
func (gco *GCOp) checkConflict( ctx context.Context, renamer ConflictRenamer, mergedOp op, isFile bool) (crAction, error) { return nil, nil }
[ "func", "(", "gco", "*", "GCOp", ")", "checkConflict", "(", "ctx", "context", ".", "Context", ",", "renamer", "ConflictRenamer", ",", "mergedOp", "op", ",", "isFile", "bool", ")", "(", "crAction", ",", "error", ")", "{", "return", "nil", ",", "nil", "\n", "}" ]
// checkConflict implements op.
[ "checkConflict", "implements", "op", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L1456-L1460
161,388
keybase/client
go/kbfs/libkbfs/ops.go
RegisterOps
func RegisterOps(codec kbfscodec.Codec) { codec.RegisterType(reflect.TypeOf(createOp{}), createOpCode) codec.RegisterType(reflect.TypeOf(rmOp{}), rmOpCode) codec.RegisterType(reflect.TypeOf(renameOp{}), renameOpCode) codec.RegisterType(reflect.TypeOf(syncOp{}), syncOpCode) codec.RegisterType(reflect.TypeOf(setAttrOp{}), setAttrOpCode) codec.RegisterType(reflect.TypeOf(resolutionOp{}), resolutionOpCode) codec.RegisterType(reflect.TypeOf(rekeyOp{}), rekeyOpCode) codec.RegisterType(reflect.TypeOf(GCOp{}), gcOpCode) codec.RegisterIfaceSliceType(reflect.TypeOf(opsList{}), opsListCode, opPointerizer) }
go
func RegisterOps(codec kbfscodec.Codec) { codec.RegisterType(reflect.TypeOf(createOp{}), createOpCode) codec.RegisterType(reflect.TypeOf(rmOp{}), rmOpCode) codec.RegisterType(reflect.TypeOf(renameOp{}), renameOpCode) codec.RegisterType(reflect.TypeOf(syncOp{}), syncOpCode) codec.RegisterType(reflect.TypeOf(setAttrOp{}), setAttrOpCode) codec.RegisterType(reflect.TypeOf(resolutionOp{}), resolutionOpCode) codec.RegisterType(reflect.TypeOf(rekeyOp{}), rekeyOpCode) codec.RegisterType(reflect.TypeOf(GCOp{}), gcOpCode) codec.RegisterIfaceSliceType(reflect.TypeOf(opsList{}), opsListCode, opPointerizer) }
[ "func", "RegisterOps", "(", "codec", "kbfscodec", ".", "Codec", ")", "{", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "createOp", "{", "}", ")", ",", "createOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "rmOp", "{", "}", ")", ",", "rmOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "renameOp", "{", "}", ")", ",", "renameOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "syncOp", "{", "}", ")", ",", "syncOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "setAttrOp", "{", "}", ")", ",", "setAttrOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "resolutionOp", "{", "}", ")", ",", "resolutionOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "rekeyOp", "{", "}", ")", ",", "rekeyOpCode", ")", "\n", "codec", ".", "RegisterType", "(", "reflect", ".", "TypeOf", "(", "GCOp", "{", "}", ")", ",", "gcOpCode", ")", "\n", "codec", ".", "RegisterIfaceSliceType", "(", "reflect", ".", "TypeOf", "(", "opsList", "{", "}", ")", ",", "opsListCode", ",", "opPointerizer", ")", "\n", "}" ]
// RegisterOps registers all op types with the given codec.
[ "RegisterOps", "registers", "all", "op", "types", "with", "the", "given", "codec", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ops.go#L1563-L1574
161,389
keybase/client
go/service/account.go
EnterResetPipeline
func (h *AccountHandler) EnterResetPipeline(ctx context.Context, arg keybase1.EnterResetPipelineArg) (err error) { mctx := libkb.NewMetaContext(ctx, h.G()) defer mctx.TraceTimed("EnterResetPipline", func() error { return err })() uis := libkb.UIs{ LoginUI: h.getLoginUI(arg.SessionID), SecretUI: h.getSecretUI(arg.SessionID, h.G()), LogUI: h.getLogUI(arg.SessionID), SessionID: arg.SessionID, } eng := engine.NewAccountReset(h.G(), arg.UsernameOrEmail) m := libkb.NewMetaContext(ctx, h.G()).WithUIs(uis) return engine.RunEngine2(m, eng) }
go
func (h *AccountHandler) EnterResetPipeline(ctx context.Context, arg keybase1.EnterResetPipelineArg) (err error) { mctx := libkb.NewMetaContext(ctx, h.G()) defer mctx.TraceTimed("EnterResetPipline", func() error { return err })() uis := libkb.UIs{ LoginUI: h.getLoginUI(arg.SessionID), SecretUI: h.getSecretUI(arg.SessionID, h.G()), LogUI: h.getLogUI(arg.SessionID), SessionID: arg.SessionID, } eng := engine.NewAccountReset(h.G(), arg.UsernameOrEmail) m := libkb.NewMetaContext(ctx, h.G()).WithUIs(uis) return engine.RunEngine2(m, eng) }
[ "func", "(", "h", "*", "AccountHandler", ")", "EnterResetPipeline", "(", "ctx", "context", ".", "Context", ",", "arg", "keybase1", ".", "EnterResetPipelineArg", ")", "(", "err", "error", ")", "{", "mctx", ":=", "libkb", ".", "NewMetaContext", "(", "ctx", ",", "h", ".", "G", "(", ")", ")", "\n", "defer", "mctx", ".", "TraceTimed", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "return", "err", "}", ")", "(", ")", "\n", "uis", ":=", "libkb", ".", "UIs", "{", "LoginUI", ":", "h", ".", "getLoginUI", "(", "arg", ".", "SessionID", ")", ",", "SecretUI", ":", "h", ".", "getSecretUI", "(", "arg", ".", "SessionID", ",", "h", ".", "G", "(", ")", ")", ",", "LogUI", ":", "h", ".", "getLogUI", "(", "arg", ".", "SessionID", ")", ",", "SessionID", ":", "arg", ".", "SessionID", ",", "}", "\n", "eng", ":=", "engine", ".", "NewAccountReset", "(", "h", ".", "G", "(", ")", ",", "arg", ".", "UsernameOrEmail", ")", "\n", "m", ":=", "libkb", ".", "NewMetaContext", "(", "ctx", ",", "h", ".", "G", "(", ")", ")", ".", "WithUIs", "(", "uis", ")", "\n", "return", "engine", ".", "RunEngine2", "(", "m", ",", "eng", ")", "\n", "}" ]
// EnterPipeline allows a user to enter the reset pipeline. The user must // verify ownership of the account via an email confirmation or their password. // Resets are not allowed on a provisioned device.
[ "EnterPipeline", "allows", "a", "user", "to", "enter", "the", "reset", "pipeline", ".", "The", "user", "must", "verify", "ownership", "of", "the", "account", "via", "an", "email", "confirmation", "or", "their", "password", ".", "Resets", "are", "not", "allowed", "on", "a", "provisioned", "device", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/account.go#L217-L229
161,390
keybase/client
go/service/account.go
CancelReset
func (h *AccountHandler) CancelReset(ctx context.Context, sessionID int) error { mctx := libkb.NewMetaContext(ctx, h.G()) return libkb.CancelResetPipeline(mctx) }
go
func (h *AccountHandler) CancelReset(ctx context.Context, sessionID int) error { mctx := libkb.NewMetaContext(ctx, h.G()) return libkb.CancelResetPipeline(mctx) }
[ "func", "(", "h", "*", "AccountHandler", ")", "CancelReset", "(", "ctx", "context", ".", "Context", ",", "sessionID", "int", ")", "error", "{", "mctx", ":=", "libkb", ".", "NewMetaContext", "(", "ctx", ",", "h", ".", "G", "(", ")", ")", "\n", "return", "libkb", ".", "CancelResetPipeline", "(", "mctx", ")", "\n", "}" ]
// CancelReset allows a user to cancel the reset process via an authenticated API call.
[ "CancelReset", "allows", "a", "user", "to", "cancel", "the", "reset", "process", "via", "an", "authenticated", "API", "call", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/account.go#L232-L235
161,391
keybase/client
go/pvl/helpers.go
selectionText
func selectionText(selection *goquery.Selection) string { var results []string selection.Each(func(i int, element *goquery.Selection) { results = append(results, element.Text()) }) return strings.Join(results, " ") }
go
func selectionText(selection *goquery.Selection) string { var results []string selection.Each(func(i int, element *goquery.Selection) { results = append(results, element.Text()) }) return strings.Join(results, " ") }
[ "func", "selectionText", "(", "selection", "*", "goquery", ".", "Selection", ")", "string", "{", "var", "results", "[", "]", "string", "\n", "selection", ".", "Each", "(", "func", "(", "i", "int", ",", "element", "*", "goquery", ".", "Selection", ")", "{", "results", "=", "append", "(", "results", ",", "element", ".", "Text", "(", ")", ")", "\n", "}", ")", "\n", "return", "strings", ".", "Join", "(", "results", ",", "\"", "\"", ")", "\n", "}" ]
// selectionText gets the Text of all elements in a selection, concatenated by a space. // The result can be an empty string.
[ "selectionText", "gets", "the", "Text", "of", "all", "elements", "in", "a", "selection", "concatenated", "by", "a", "space", ".", "The", "result", "can", "be", "an", "empty", "string", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/helpers.go#L68-L74
161,392
keybase/client
go/pvl/helpers.go
selectionAttr
func selectionAttr(selection *goquery.Selection, attr string) string { var results []string selection.Each(func(i int, element *goquery.Selection) { res, ok := element.Attr(attr) if ok { results = append(results, res) } }) return strings.Join(results, " ") }
go
func selectionAttr(selection *goquery.Selection, attr string) string { var results []string selection.Each(func(i int, element *goquery.Selection) { res, ok := element.Attr(attr) if ok { results = append(results, res) } }) return strings.Join(results, " ") }
[ "func", "selectionAttr", "(", "selection", "*", "goquery", ".", "Selection", ",", "attr", "string", ")", "string", "{", "var", "results", "[", "]", "string", "\n", "selection", ".", "Each", "(", "func", "(", "i", "int", ",", "element", "*", "goquery", ".", "Selection", ")", "{", "res", ",", "ok", ":=", "element", ".", "Attr", "(", "attr", ")", "\n", "if", "ok", "{", "results", "=", "append", "(", "results", ",", "res", ")", "\n", "}", "\n", "}", ")", "\n", "return", "strings", ".", "Join", "(", "results", ",", "\"", "\"", ")", "\n", "}" ]
// selectionAttr gets the specified attr of all elements in a selection, concatenated by a space. // If getting the attr of any elements fails, that does not cause an error. // The result can be an empty string.
[ "selectionAttr", "gets", "the", "specified", "attr", "of", "all", "elements", "in", "a", "selection", "concatenated", "by", "a", "space", ".", "If", "getting", "the", "attr", "of", "any", "elements", "fails", "that", "does", "not", "cause", "an", "error", ".", "The", "result", "can", "be", "an", "empty", "string", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/helpers.go#L79-L88
161,393
keybase/client
go/pvl/helpers.go
selectionData
func selectionData(selection *goquery.Selection) string { var results []string selection.Each(func(i int, element *goquery.Selection) { if len(element.Nodes) > 0 { results = append(results, element.Nodes[0].Data) } }) return strings.Join(results, " ") }
go
func selectionData(selection *goquery.Selection) string { var results []string selection.Each(func(i int, element *goquery.Selection) { if len(element.Nodes) > 0 { results = append(results, element.Nodes[0].Data) } }) return strings.Join(results, " ") }
[ "func", "selectionData", "(", "selection", "*", "goquery", ".", "Selection", ")", "string", "{", "var", "results", "[", "]", "string", "\n", "selection", ".", "Each", "(", "func", "(", "i", "int", ",", "element", "*", "goquery", ".", "Selection", ")", "{", "if", "len", "(", "element", ".", "Nodes", ")", ">", "0", "{", "results", "=", "append", "(", "results", ",", "element", ".", "Nodes", "[", "0", "]", ".", "Data", ")", "\n", "}", "\n", "}", ")", "\n", "return", "strings", ".", "Join", "(", "results", ",", "\"", "\"", ")", "\n", "}" ]
// selectionData gets the first node's data of all elements in a selection, concatenated by a space. // The result can be an empty string.
[ "selectionData", "gets", "the", "first", "node", "s", "data", "of", "all", "elements", "in", "a", "selection", "concatenated", "by", "a", "space", ".", "The", "result", "can", "be", "an", "empty", "string", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/helpers.go#L92-L100
161,394
keybase/client
go/pvl/helpers.go
validateDomain
func validateDomain(s string) bool { // Throw a protocol in front because the parser wants one. proto := "http" u, err := url.Parse(proto + "://" + s) if err != nil { return false } // The final group must include a non-numeric character. // To disallow the likes of "8.8.8.8." dotsplit := strings.Split(strings.TrimSuffix(u.Host, "."), ".") if len(dotsplit) > 0 { group := dotsplit[len(dotsplit)-1] if !hasalpha.MatchString(group) { return false } } ok := (u.IsAbs()) && (u.Scheme == proto) && (u.User == nil) && (u.Path == "") && (u.RawPath == "") && (u.RawQuery == "") && (u.Fragment == "") && // Disallow colons. So no port, and no ipv6. (!strings.Contains(u.Host, ":")) && // Disallow any valid ip addresses. (net.ParseIP(u.Host) == nil) return ok }
go
func validateDomain(s string) bool { // Throw a protocol in front because the parser wants one. proto := "http" u, err := url.Parse(proto + "://" + s) if err != nil { return false } // The final group must include a non-numeric character. // To disallow the likes of "8.8.8.8." dotsplit := strings.Split(strings.TrimSuffix(u.Host, "."), ".") if len(dotsplit) > 0 { group := dotsplit[len(dotsplit)-1] if !hasalpha.MatchString(group) { return false } } ok := (u.IsAbs()) && (u.Scheme == proto) && (u.User == nil) && (u.Path == "") && (u.RawPath == "") && (u.RawQuery == "") && (u.Fragment == "") && // Disallow colons. So no port, and no ipv6. (!strings.Contains(u.Host, ":")) && // Disallow any valid ip addresses. (net.ParseIP(u.Host) == nil) return ok }
[ "func", "validateDomain", "(", "s", "string", ")", "bool", "{", "// Throw a protocol in front because the parser wants one.", "proto", ":=", "\"", "\"", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "proto", "+", "\"", "\"", "+", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "// The final group must include a non-numeric character.", "// To disallow the likes of \"8.8.8.8.\"", "dotsplit", ":=", "strings", ".", "Split", "(", "strings", ".", "TrimSuffix", "(", "u", ".", "Host", ",", "\"", "\"", ")", ",", "\"", "\"", ")", "\n", "if", "len", "(", "dotsplit", ")", ">", "0", "{", "group", ":=", "dotsplit", "[", "len", "(", "dotsplit", ")", "-", "1", "]", "\n", "if", "!", "hasalpha", ".", "MatchString", "(", "group", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "ok", ":=", "(", "u", ".", "IsAbs", "(", ")", ")", "&&", "(", "u", ".", "Scheme", "==", "proto", ")", "&&", "(", "u", ".", "User", "==", "nil", ")", "&&", "(", "u", ".", "Path", "==", "\"", "\"", ")", "&&", "(", "u", ".", "RawPath", "==", "\"", "\"", ")", "&&", "(", "u", ".", "RawQuery", "==", "\"", "\"", ")", "&&", "(", "u", ".", "Fragment", "==", "\"", "\"", ")", "&&", "// Disallow colons. So no port, and no ipv6.", "(", "!", "strings", ".", "Contains", "(", "u", ".", "Host", ",", "\"", "\"", ")", ")", "&&", "// Disallow any valid ip addresses.", "(", "net", ".", "ParseIP", "(", "u", ".", "Host", ")", "==", "nil", ")", "\n", "return", "ok", "\n", "}" ]
// Check that a url is valid and has only a domain and is not an ip. // No port, path, protocol, user, query, or any other junk is allowed.
[ "Check", "that", "a", "url", "is", "valid", "and", "has", "only", "a", "domain", "and", "is", "not", "an", "ip", ".", "No", "port", "path", "protocol", "user", "query", "or", "any", "other", "junk", "is", "allowed", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/helpers.go#L115-L145
161,395
keybase/client
go/pvl/helpers.go
validateProtocol
func validateProtocol(s string, allowed []string) (string, bool) { canons := map[string]string{ "http": "http", "https": "https", "dns": "dns", "http:": "http", "https:": "https", "dns:": "dns", "http://": "http", "https://": "https", "dns://": "dns", } canon, ok := canons[s] if ok { return canon, stringsContains(allowed, canon) } return canon, false }
go
func validateProtocol(s string, allowed []string) (string, bool) { canons := map[string]string{ "http": "http", "https": "https", "dns": "dns", "http:": "http", "https:": "https", "dns:": "dns", "http://": "http", "https://": "https", "dns://": "dns", } canon, ok := canons[s] if ok { return canon, stringsContains(allowed, canon) } return canon, false }
[ "func", "validateProtocol", "(", "s", "string", ",", "allowed", "[", "]", "string", ")", "(", "string", ",", "bool", ")", "{", "canons", ":=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", "\n\n", "canon", ",", "ok", ":=", "canons", "[", "s", "]", "\n", "if", "ok", "{", "return", "canon", ",", "stringsContains", "(", "allowed", ",", "canon", ")", "\n", "}", "\n", "return", "canon", ",", "false", "\n", "}" ]
// validateProtocol takes a protocol and returns the canonicalized form and whether it is valid.
[ "validateProtocol", "takes", "a", "protocol", "and", "returns", "the", "canonicalized", "form", "and", "whether", "it", "is", "valid", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/pvl/helpers.go#L148-L166
161,396
keybase/client
go/engine/puk_upgrade.go
NewPerUserKeyUpgrade
func NewPerUserKeyUpgrade(g *libkb.GlobalContext, args *PerUserKeyUpgradeArgs) *PerUserKeyUpgrade { return &PerUserKeyUpgrade{ args: args, Contextified: libkb.NewContextified(g), } }
go
func NewPerUserKeyUpgrade(g *libkb.GlobalContext, args *PerUserKeyUpgradeArgs) *PerUserKeyUpgrade { return &PerUserKeyUpgrade{ args: args, Contextified: libkb.NewContextified(g), } }
[ "func", "NewPerUserKeyUpgrade", "(", "g", "*", "libkb", ".", "GlobalContext", ",", "args", "*", "PerUserKeyUpgradeArgs", ")", "*", "PerUserKeyUpgrade", "{", "return", "&", "PerUserKeyUpgrade", "{", "args", ":", "args", ",", "Contextified", ":", "libkb", ".", "NewContextified", "(", "g", ")", ",", "}", "\n", "}" ]
// NewPerUserKeyUpgrade creates a PerUserKeyUpgrade engine.
[ "NewPerUserKeyUpgrade", "creates", "a", "PerUserKeyUpgrade", "engine", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/puk_upgrade.go#L25-L30
161,397
keybase/client
go/libkb/active_device.go
NewProvisionalActiveDevice
func NewProvisionalActiveDevice(m MetaContext, uv keybase1.UserVersion, d keybase1.DeviceID, sigKey GenericKey, encKey GenericKey, deviceName string) *ActiveDevice { return &ActiveDevice{ uv: uv, deviceID: d, deviceName: deviceName, signingKey: sigKey, encryptionKey: encKey, nistFactory: NewNISTFactory(m.G(), uv.Uid, d, sigKey), secretSyncer: NewSecretSyncer(m.G()), } }
go
func NewProvisionalActiveDevice(m MetaContext, uv keybase1.UserVersion, d keybase1.DeviceID, sigKey GenericKey, encKey GenericKey, deviceName string) *ActiveDevice { return &ActiveDevice{ uv: uv, deviceID: d, deviceName: deviceName, signingKey: sigKey, encryptionKey: encKey, nistFactory: NewNISTFactory(m.G(), uv.Uid, d, sigKey), secretSyncer: NewSecretSyncer(m.G()), } }
[ "func", "NewProvisionalActiveDevice", "(", "m", "MetaContext", ",", "uv", "keybase1", ".", "UserVersion", ",", "d", "keybase1", ".", "DeviceID", ",", "sigKey", "GenericKey", ",", "encKey", "GenericKey", ",", "deviceName", "string", ")", "*", "ActiveDevice", "{", "return", "&", "ActiveDevice", "{", "uv", ":", "uv", ",", "deviceID", ":", "d", ",", "deviceName", ":", "deviceName", ",", "signingKey", ":", "sigKey", ",", "encryptionKey", ":", "encKey", ",", "nistFactory", ":", "NewNISTFactory", "(", "m", ".", "G", "(", ")", ",", "uv", ".", "Uid", ",", "d", ",", "sigKey", ")", ",", "secretSyncer", ":", "NewSecretSyncer", "(", "m", ".", "G", "(", ")", ")", ",", "}", "\n", "}" ]
// NewProvisionalActiveDevice creates an ActiveDevice that is "provisional", in // that it should not be considered the global ActiveDevice. Instead, it should // reside in thread-local context, and can be weaved through the login // machinery without trampling the actual global ActiveDevice.
[ "NewProvisionalActiveDevice", "creates", "an", "ActiveDevice", "that", "is", "provisional", "in", "that", "it", "should", "not", "be", "considered", "the", "global", "ActiveDevice", ".", "Instead", "it", "should", "reside", "in", "thread", "-", "local", "context", "and", "can", "be", "weaved", "through", "the", "login", "machinery", "without", "trampling", "the", "actual", "global", "ActiveDevice", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/active_device.go#L51-L61
161,398
keybase/client
go/libkb/active_device.go
Copy
func (a *ActiveDevice) Copy(m MetaContext, src *ActiveDevice) error { // Take a consistent snapshot of the src device. Be careful not to hold // locks on both devices at once. src.Lock() uv := src.uv deviceID := src.deviceID sigKey := src.signingKey encKey := src.encryptionKey name := src.deviceName ctime := src.deviceCtime src.Unlock() return a.Set(m, uv, deviceID, sigKey, encKey, name, ctime) }
go
func (a *ActiveDevice) Copy(m MetaContext, src *ActiveDevice) error { // Take a consistent snapshot of the src device. Be careful not to hold // locks on both devices at once. src.Lock() uv := src.uv deviceID := src.deviceID sigKey := src.signingKey encKey := src.encryptionKey name := src.deviceName ctime := src.deviceCtime src.Unlock() return a.Set(m, uv, deviceID, sigKey, encKey, name, ctime) }
[ "func", "(", "a", "*", "ActiveDevice", ")", "Copy", "(", "m", "MetaContext", ",", "src", "*", "ActiveDevice", ")", "error", "{", "// Take a consistent snapshot of the src device. Be careful not to hold", "// locks on both devices at once.", "src", ".", "Lock", "(", ")", "\n", "uv", ":=", "src", ".", "uv", "\n", "deviceID", ":=", "src", ".", "deviceID", "\n", "sigKey", ":=", "src", ".", "signingKey", "\n", "encKey", ":=", "src", ".", "encryptionKey", "\n", "name", ":=", "src", ".", "deviceName", "\n", "ctime", ":=", "src", ".", "deviceCtime", "\n", "src", ".", "Unlock", "(", ")", "\n\n", "return", "a", ".", "Set", "(", "m", ",", "uv", ",", "deviceID", ",", "sigKey", ",", "encKey", ",", "name", ",", "ctime", ")", "\n", "}" ]
// Copy ActiveDevice info from the given ActiveDevice.
[ "Copy", "ActiveDevice", "info", "from", "the", "given", "ActiveDevice", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/active_device.go#L94-L108
161,399
keybase/client
go/libkb/active_device.go
Set
func (a *ActiveDevice) Set(m MetaContext, uv keybase1.UserVersion, deviceID keybase1.DeviceID, sigKey, encKey GenericKey, deviceName string, deviceCtime keybase1.Time) error { a.Lock() defer a.Unlock() if err := a.internalUpdateUserVersionDeviceID(uv, deviceID); err != nil { return err } a.signingKey = sigKey a.encryptionKey = encKey a.deviceName = deviceName a.deviceCtime = deviceCtime a.nistFactory = NewNISTFactory(m.G(), uv.Uid, deviceID, sigKey) a.secretSyncer = NewSecretSyncer(m.G()) return nil }
go
func (a *ActiveDevice) Set(m MetaContext, uv keybase1.UserVersion, deviceID keybase1.DeviceID, sigKey, encKey GenericKey, deviceName string, deviceCtime keybase1.Time) error { a.Lock() defer a.Unlock() if err := a.internalUpdateUserVersionDeviceID(uv, deviceID); err != nil { return err } a.signingKey = sigKey a.encryptionKey = encKey a.deviceName = deviceName a.deviceCtime = deviceCtime a.nistFactory = NewNISTFactory(m.G(), uv.Uid, deviceID, sigKey) a.secretSyncer = NewSecretSyncer(m.G()) return nil }
[ "func", "(", "a", "*", "ActiveDevice", ")", "Set", "(", "m", "MetaContext", ",", "uv", "keybase1", ".", "UserVersion", ",", "deviceID", "keybase1", ".", "DeviceID", ",", "sigKey", ",", "encKey", "GenericKey", ",", "deviceName", "string", ",", "deviceCtime", "keybase1", ".", "Time", ")", "error", "{", "a", ".", "Lock", "(", ")", "\n", "defer", "a", ".", "Unlock", "(", ")", "\n\n", "if", "err", ":=", "a", ".", "internalUpdateUserVersionDeviceID", "(", "uv", ",", "deviceID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "a", ".", "signingKey", "=", "sigKey", "\n", "a", ".", "encryptionKey", "=", "encKey", "\n", "a", ".", "deviceName", "=", "deviceName", "\n", "a", ".", "deviceCtime", "=", "deviceCtime", "\n", "a", ".", "nistFactory", "=", "NewNISTFactory", "(", "m", ".", "G", "(", ")", ",", "uv", ".", "Uid", ",", "deviceID", ",", "sigKey", ")", "\n", "a", ".", "secretSyncer", "=", "NewSecretSyncer", "(", "m", ".", "G", "(", ")", ")", "\n\n", "return", "nil", "\n", "}" ]
// Set acquires the write lock and sets all the fields in ActiveDevice. // The acct parameter is not used for anything except to help ensure // that this is called from inside a LoginState account request.
[ "Set", "acquires", "the", "write", "lock", "and", "sets", "all", "the", "fields", "in", "ActiveDevice", ".", "The", "acct", "parameter", "is", "not", "used", "for", "anything", "except", "to", "help", "ensure", "that", "this", "is", "called", "from", "inside", "a", "LoginState", "account", "request", "." ]
b352622cd8cc94798cfacbcb56ada203c18e519e
https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/active_device.go#L122-L139