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
|
---|---|---|---|---|---|---|---|---|---|---|---|
159,000 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | GetTeamRootID | func (k *KBPKIClient) GetTeamRootID(
ctx context.Context, tid keybase1.TeamID,
offline keybase1.OfflineAvailability) (keybase1.TeamID, error) {
if !tid.IsSubTeam() {
return tid, nil
}
teamInfo, err := k.serviceOwner.KeybaseService().LoadTeamPlusKeys(
ctx, tid, tlf.Unknown, kbfsmd.UnspecifiedKeyGen, keybase1.UserVersion{},
kbfscrypto.VerifyingKey{}, keybase1.TeamRole_NONE, offline)
if err != nil {
return keybase1.TeamID(""), err
}
return teamInfo.RootID, nil
} | go | func (k *KBPKIClient) GetTeamRootID(
ctx context.Context, tid keybase1.TeamID,
offline keybase1.OfflineAvailability) (keybase1.TeamID, error) {
if !tid.IsSubTeam() {
return tid, nil
}
teamInfo, err := k.serviceOwner.KeybaseService().LoadTeamPlusKeys(
ctx, tid, tlf.Unknown, kbfsmd.UnspecifiedKeyGen, keybase1.UserVersion{},
kbfscrypto.VerifyingKey{}, keybase1.TeamRole_NONE, offline)
if err != nil {
return keybase1.TeamID(""), err
}
return teamInfo.RootID, nil
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"GetTeamRootID",
"(",
"ctx",
"context",
".",
"Context",
",",
"tid",
"keybase1",
".",
"TeamID",
",",
"offline",
"keybase1",
".",
"OfflineAvailability",
")",
"(",
"keybase1",
".",
"TeamID",
",",
"error",
")",
"{",
"if",
"!",
"tid",
".",
"IsSubTeam",
"(",
")",
"{",
"return",
"tid",
",",
"nil",
"\n",
"}",
"\n\n",
"teamInfo",
",",
"err",
":=",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"LoadTeamPlusKeys",
"(",
"ctx",
",",
"tid",
",",
"tlf",
".",
"Unknown",
",",
"kbfsmd",
".",
"UnspecifiedKeyGen",
",",
"keybase1",
".",
"UserVersion",
"{",
"}",
",",
"kbfscrypto",
".",
"VerifyingKey",
"{",
"}",
",",
"keybase1",
".",
"TeamRole_NONE",
",",
"offline",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"keybase1",
".",
"TeamID",
"(",
"\"",
"\"",
")",
",",
"err",
"\n",
"}",
"\n",
"return",
"teamInfo",
".",
"RootID",
",",
"nil",
"\n",
"}"
] | // GetTeamRootID implements the KBPKI interface for KBPKIClient. | [
"GetTeamRootID",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L366-L380 |
159,001 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | CreateTeamTLF | func (k *KBPKIClient) CreateTeamTLF(
ctx context.Context, teamID keybase1.TeamID, tlfID tlf.ID) error {
return k.serviceOwner.KeybaseService().CreateTeamTLF(ctx, teamID, tlfID)
} | go | func (k *KBPKIClient) CreateTeamTLF(
ctx context.Context, teamID keybase1.TeamID, tlfID tlf.ID) error {
return k.serviceOwner.KeybaseService().CreateTeamTLF(ctx, teamID, tlfID)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"CreateTeamTLF",
"(",
"ctx",
"context",
".",
"Context",
",",
"teamID",
"keybase1",
".",
"TeamID",
",",
"tlfID",
"tlf",
".",
"ID",
")",
"error",
"{",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"CreateTeamTLF",
"(",
"ctx",
",",
"teamID",
",",
"tlfID",
")",
"\n",
"}"
] | // CreateTeamTLF implements the KBPKI interface for KBPKIClient. | [
"CreateTeamTLF",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L383-L386 |
159,002 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | FavoriteAdd | func (k *KBPKIClient) FavoriteAdd(ctx context.Context, folder keybase1.Folder) error {
return k.serviceOwner.KeybaseService().FavoriteAdd(ctx, folder)
} | go | func (k *KBPKIClient) FavoriteAdd(ctx context.Context, folder keybase1.Folder) error {
return k.serviceOwner.KeybaseService().FavoriteAdd(ctx, folder)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"FavoriteAdd",
"(",
"ctx",
"context",
".",
"Context",
",",
"folder",
"keybase1",
".",
"Folder",
")",
"error",
"{",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"FavoriteAdd",
"(",
"ctx",
",",
"folder",
")",
"\n",
"}"
] | // FavoriteAdd implements the KBPKI interface for KBPKIClient. | [
"FavoriteAdd",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L389-L391 |
159,003 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | FavoriteList | func (k *KBPKIClient) FavoriteList(ctx context.Context) (
keybase1.FavoritesResult, error) {
const sessionID = 0
return k.serviceOwner.KeybaseService().FavoriteList(ctx, sessionID)
} | go | func (k *KBPKIClient) FavoriteList(ctx context.Context) (
keybase1.FavoritesResult, error) {
const sessionID = 0
return k.serviceOwner.KeybaseService().FavoriteList(ctx, sessionID)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"FavoriteList",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"keybase1",
".",
"FavoritesResult",
",",
"error",
")",
"{",
"const",
"sessionID",
"=",
"0",
"\n",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"FavoriteList",
"(",
"ctx",
",",
"sessionID",
")",
"\n",
"}"
] | // FavoriteList implements the KBPKI interface for KBPKIClient. | [
"FavoriteList",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L399-L403 |
159,004 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | Notify | func (k *KBPKIClient) Notify(ctx context.Context, notification *keybase1.FSNotification) error {
return k.serviceOwner.KeybaseService().Notify(ctx, notification)
} | go | func (k *KBPKIClient) Notify(ctx context.Context, notification *keybase1.FSNotification) error {
return k.serviceOwner.KeybaseService().Notify(ctx, notification)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"Notify",
"(",
"ctx",
"context",
".",
"Context",
",",
"notification",
"*",
"keybase1",
".",
"FSNotification",
")",
"error",
"{",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"Notify",
"(",
"ctx",
",",
"notification",
")",
"\n",
"}"
] | // Notify implements the KBPKI interface for KBPKIClient. | [
"Notify",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L406-L408 |
159,005 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | NotifyPathUpdated | func (k *KBPKIClient) NotifyPathUpdated(
ctx context.Context, path string) error {
return k.serviceOwner.KeybaseService().NotifyPathUpdated(ctx, path)
} | go | func (k *KBPKIClient) NotifyPathUpdated(
ctx context.Context, path string) error {
return k.serviceOwner.KeybaseService().NotifyPathUpdated(ctx, path)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"NotifyPathUpdated",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"error",
"{",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"NotifyPathUpdated",
"(",
"ctx",
",",
"path",
")",
"\n",
"}"
] | // NotifyPathUpdated implements the KBPKI interface for KBPKIClient. | [
"NotifyPathUpdated",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L411-L414 |
159,006 | keybase/client | go/kbfs/libkbfs/kbpki_client.go | PutGitMetadata | func (k *KBPKIClient) PutGitMetadata(
ctx context.Context, folder keybase1.Folder, repoID keybase1.RepoID,
metadata keybase1.GitLocalMetadata) error {
return k.serviceOwner.KeybaseService().PutGitMetadata(
ctx, folder, repoID, metadata)
} | go | func (k *KBPKIClient) PutGitMetadata(
ctx context.Context, folder keybase1.Folder, repoID keybase1.RepoID,
metadata keybase1.GitLocalMetadata) error {
return k.serviceOwner.KeybaseService().PutGitMetadata(
ctx, folder, repoID, metadata)
} | [
"func",
"(",
"k",
"*",
"KBPKIClient",
")",
"PutGitMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"folder",
"keybase1",
".",
"Folder",
",",
"repoID",
"keybase1",
".",
"RepoID",
",",
"metadata",
"keybase1",
".",
"GitLocalMetadata",
")",
"error",
"{",
"return",
"k",
".",
"serviceOwner",
".",
"KeybaseService",
"(",
")",
".",
"PutGitMetadata",
"(",
"ctx",
",",
"folder",
",",
"repoID",
",",
"metadata",
")",
"\n",
"}"
] | // PutGitMetadata implements the KBPKI interface for KBPKIClient. | [
"PutGitMetadata",
"implements",
"the",
"KBPKI",
"interface",
"for",
"KBPKIClient",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/kbpki_client.go#L417-L422 |
159,007 | keybase/client | go/service/pprof.go | doTimedProfile | func doTimedProfile(log libkb.LogUI, delayedLog logger.Logger,
profiler timedProfiler, outputFile string,
durationSeconds keybase1.DurationSec) (err error) {
if !filepath.IsAbs(outputFile) {
return fmt.Errorf("%q is not an absolute path", outputFile)
}
close := func(c io.Closer) {
err := c.Close()
if err != nil {
log.Warning("Failed to close %s: %s", outputFile, err)
}
}
name := profiler.Name()
defer func() {
if err != nil {
log.Warning("Failed to do %s profile to %s for %.2f second(s): %s", name, outputFile, durationSeconds, err)
}
}()
f, err := os.Create(outputFile)
if err != nil {
return err
}
err = profiler.Start(f)
if err != nil {
close(f)
return err
}
log.Info("Doing %s profile to %s for %.2f second(s)", name, outputFile, durationSeconds)
go func() {
time.Sleep(durationSecToDuration(durationSeconds))
profiler.Stop()
close(f)
delayedLog.Info("%s profile to %s done", name, outputFile)
}()
return nil
} | go | func doTimedProfile(log libkb.LogUI, delayedLog logger.Logger,
profiler timedProfiler, outputFile string,
durationSeconds keybase1.DurationSec) (err error) {
if !filepath.IsAbs(outputFile) {
return fmt.Errorf("%q is not an absolute path", outputFile)
}
close := func(c io.Closer) {
err := c.Close()
if err != nil {
log.Warning("Failed to close %s: %s", outputFile, err)
}
}
name := profiler.Name()
defer func() {
if err != nil {
log.Warning("Failed to do %s profile to %s for %.2f second(s): %s", name, outputFile, durationSeconds, err)
}
}()
f, err := os.Create(outputFile)
if err != nil {
return err
}
err = profiler.Start(f)
if err != nil {
close(f)
return err
}
log.Info("Doing %s profile to %s for %.2f second(s)", name, outputFile, durationSeconds)
go func() {
time.Sleep(durationSecToDuration(durationSeconds))
profiler.Stop()
close(f)
delayedLog.Info("%s profile to %s done", name, outputFile)
}()
return nil
} | [
"func",
"doTimedProfile",
"(",
"log",
"libkb",
".",
"LogUI",
",",
"delayedLog",
"logger",
".",
"Logger",
",",
"profiler",
"timedProfiler",
",",
"outputFile",
"string",
",",
"durationSeconds",
"keybase1",
".",
"DurationSec",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"outputFile",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"outputFile",
")",
"\n",
"}",
"\n\n",
"close",
":=",
"func",
"(",
"c",
"io",
".",
"Closer",
")",
"{",
"err",
":=",
"c",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warning",
"(",
"\"",
"\"",
",",
"outputFile",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"name",
":=",
"profiler",
".",
"Name",
"(",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warning",
"(",
"\"",
"\"",
",",
"name",
",",
"outputFile",
",",
"durationSeconds",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"outputFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"profiler",
".",
"Start",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"close",
"(",
"f",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"name",
",",
"outputFile",
",",
"durationSeconds",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"durationSecToDuration",
"(",
"durationSeconds",
")",
")",
"\n",
"profiler",
".",
"Stop",
"(",
")",
"\n",
"close",
"(",
"f",
")",
"\n",
"delayedLog",
".",
"Info",
"(",
"\"",
"\"",
",",
"name",
",",
"outputFile",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // doTimedProfile asynchronously runs a profile with the given
// timedProfiler and associated parameters. | [
"doTimedProfile",
"asynchronously",
"runs",
"a",
"profile",
"with",
"the",
"given",
"timedProfiler",
"and",
"associated",
"parameters",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/service/pprof.go#L51-L94 |
159,008 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | NewMDServerDir | func NewMDServerDir(
config mdServerLocalConfig, dirPath string) (*MDServerDisk, error) {
return newMDServerDisk(config, dirPath, nil)
} | go | func NewMDServerDir(
config mdServerLocalConfig, dirPath string) (*MDServerDisk, error) {
return newMDServerDisk(config, dirPath, nil)
} | [
"func",
"NewMDServerDir",
"(",
"config",
"mdServerLocalConfig",
",",
"dirPath",
"string",
")",
"(",
"*",
"MDServerDisk",
",",
"error",
")",
"{",
"return",
"newMDServerDisk",
"(",
"config",
",",
"dirPath",
",",
"nil",
")",
"\n",
"}"
] | // NewMDServerDir constructs a new MDServerDisk that stores its data
// in the given directory. | [
"NewMDServerDir",
"constructs",
"a",
"new",
"MDServerDisk",
"that",
"stores",
"its",
"data",
"in",
"the",
"given",
"directory",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L91-L94 |
159,009 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | NewMDServerTempDir | func NewMDServerTempDir(config mdServerLocalConfig) (*MDServerDisk, error) {
tempdir, err := ioutil.TempDir(os.TempDir(), "kbfs_mdserver_tmp")
if err != nil {
return nil, err
}
return newMDServerDisk(config, tempdir, func(log logger.Logger) {
err := ioutil.RemoveAll(tempdir)
if err != nil {
log.Warning("error removing %s: %s", tempdir, err)
}
})
} | go | func NewMDServerTempDir(config mdServerLocalConfig) (*MDServerDisk, error) {
tempdir, err := ioutil.TempDir(os.TempDir(), "kbfs_mdserver_tmp")
if err != nil {
return nil, err
}
return newMDServerDisk(config, tempdir, func(log logger.Logger) {
err := ioutil.RemoveAll(tempdir)
if err != nil {
log.Warning("error removing %s: %s", tempdir, err)
}
})
} | [
"func",
"NewMDServerTempDir",
"(",
"config",
"mdServerLocalConfig",
")",
"(",
"*",
"MDServerDisk",
",",
"error",
")",
"{",
"tempdir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"os",
".",
"TempDir",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newMDServerDisk",
"(",
"config",
",",
"tempdir",
",",
"func",
"(",
"log",
"logger",
".",
"Logger",
")",
"{",
"err",
":=",
"ioutil",
".",
"RemoveAll",
"(",
"tempdir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warning",
"(",
"\"",
"\"",
",",
"tempdir",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // NewMDServerTempDir constructs a new MDServerDisk that stores its
// data in a temp directory which is cleaned up on shutdown. | [
"NewMDServerTempDir",
"constructs",
"a",
"new",
"MDServerDisk",
"that",
"stores",
"its",
"data",
"in",
"a",
"temp",
"directory",
"which",
"is",
"cleaned",
"up",
"on",
"shutdown",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L98-L109 |
159,010 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | GetForTLF | func (md *MDServerDisk) GetForTLF(ctx context.Context, id tlf.ID,
bid kbfsmd.BranchID, mStatus kbfsmd.MergeStatus, _ *keybase1.LockID) (
*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
// Lookup the branch ID if not supplied
if mStatus == kbfsmd.Unmerged && bid == kbfsmd.NullBranchID {
var err error
bid, err = md.getBranchID(ctx, id)
if err != nil {
return nil, err
}
if bid == kbfsmd.NullBranchID {
return nil, nil
}
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
return tlfStorage.getForTLF(ctx, session.UID, bid)
} | go | func (md *MDServerDisk) GetForTLF(ctx context.Context, id tlf.ID,
bid kbfsmd.BranchID, mStatus kbfsmd.MergeStatus, _ *keybase1.LockID) (
*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
// Lookup the branch ID if not supplied
if mStatus == kbfsmd.Unmerged && bid == kbfsmd.NullBranchID {
var err error
bid, err = md.getBranchID(ctx, id)
if err != nil {
return nil, err
}
if bid == kbfsmd.NullBranchID {
return nil, nil
}
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
return tlfStorage.getForTLF(ctx, session.UID, bid)
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"GetForTLF",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"tlf",
".",
"ID",
",",
"bid",
"kbfsmd",
".",
"BranchID",
",",
"mStatus",
"kbfsmd",
".",
"MergeStatus",
",",
"_",
"*",
"keybase1",
".",
"LockID",
")",
"(",
"*",
"RootMetadataSigned",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Lookup the branch ID if not supplied",
"if",
"mStatus",
"==",
"kbfsmd",
".",
"Unmerged",
"&&",
"bid",
"==",
"kbfsmd",
".",
"NullBranchID",
"{",
"var",
"err",
"error",
"\n",
"bid",
",",
"err",
"=",
"md",
".",
"getBranchID",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"bid",
"==",
"kbfsmd",
".",
"NullBranchID",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"md",
".",
"config",
".",
"currentSessionGetter",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"tlfStorage",
",",
"err",
":=",
"md",
".",
"getStorage",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"tlfStorage",
".",
"getForTLF",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"bid",
")",
"\n",
"}"
] | // GetForTLF implements the MDServer interface for MDServerDisk. | [
"GetForTLF",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L355-L385 |
159,011 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | GetForTLFByTime | func (md *MDServerDisk) GetForTLFByTime(
ctx context.Context, id tlf.ID, serverTime time.Time) (
*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
rmd, err := tlfStorage.getForTLF(ctx, session.UID, kbfsmd.NullBranchID)
if err != nil {
return nil, err
}
// Do a linear backwards search to find the RMD that comes just
// before or at `serverTime`.
for rmd.untrustedServerTimestamp.After(serverTime) {
nextRev := rmd.MD.RevisionNumber() - 1
if nextRev == kbfsmd.RevisionUninitialized {
return nil, errors.Errorf(
"No MD found for TLF %s and serverTime %s", id, serverTime)
}
mds, err := tlfStorage.getRange(
ctx, session.UID, kbfsmd.NullBranchID, nextRev, nextRev)
if err != nil {
return nil, err
}
if len(mds) != 1 {
return nil, errors.Errorf(
"No MD found for TLF %s and serverTime %s", id, serverTime)
}
rmd = mds[0]
}
return rmd, nil
} | go | func (md *MDServerDisk) GetForTLFByTime(
ctx context.Context, id tlf.ID, serverTime time.Time) (
*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
rmd, err := tlfStorage.getForTLF(ctx, session.UID, kbfsmd.NullBranchID)
if err != nil {
return nil, err
}
// Do a linear backwards search to find the RMD that comes just
// before or at `serverTime`.
for rmd.untrustedServerTimestamp.After(serverTime) {
nextRev := rmd.MD.RevisionNumber() - 1
if nextRev == kbfsmd.RevisionUninitialized {
return nil, errors.Errorf(
"No MD found for TLF %s and serverTime %s", id, serverTime)
}
mds, err := tlfStorage.getRange(
ctx, session.UID, kbfsmd.NullBranchID, nextRev, nextRev)
if err != nil {
return nil, err
}
if len(mds) != 1 {
return nil, errors.Errorf(
"No MD found for TLF %s and serverTime %s", id, serverTime)
}
rmd = mds[0]
}
return rmd, nil
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"GetForTLFByTime",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"tlf",
".",
"ID",
",",
"serverTime",
"time",
".",
"Time",
")",
"(",
"*",
"RootMetadataSigned",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"md",
".",
"config",
".",
"currentSessionGetter",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"tlfStorage",
",",
"err",
":=",
"md",
".",
"getStorage",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"rmd",
",",
"err",
":=",
"tlfStorage",
".",
"getForTLF",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"kbfsmd",
".",
"NullBranchID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Do a linear backwards search to find the RMD that comes just",
"// before or at `serverTime`.",
"for",
"rmd",
".",
"untrustedServerTimestamp",
".",
"After",
"(",
"serverTime",
")",
"{",
"nextRev",
":=",
"rmd",
".",
"MD",
".",
"RevisionNumber",
"(",
")",
"-",
"1",
"\n",
"if",
"nextRev",
"==",
"kbfsmd",
".",
"RevisionUninitialized",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
",",
"serverTime",
")",
"\n",
"}",
"\n",
"mds",
",",
"err",
":=",
"tlfStorage",
".",
"getRange",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"kbfsmd",
".",
"NullBranchID",
",",
"nextRev",
",",
"nextRev",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"mds",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
",",
"serverTime",
")",
"\n",
"}",
"\n",
"rmd",
"=",
"mds",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"rmd",
",",
"nil",
"\n",
"}"
] | // GetForTLFByTime implements the MDServer interface for MDServerDisk. | [
"GetForTLFByTime",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L388-L431 |
159,012 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | GetRange | func (md *MDServerDisk) GetRange(ctx context.Context, id tlf.ID,
bid kbfsmd.BranchID, mStatus kbfsmd.MergeStatus, start, stop kbfsmd.Revision,
_ *keybase1.LockID) ([]*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
md.log.CDebugf(ctx, "GetRange %d %d (%s)", start, stop, mStatus)
// Lookup the branch ID if not supplied
if mStatus == kbfsmd.Unmerged && bid == kbfsmd.NullBranchID {
var err error
bid, err = md.getBranchID(ctx, id)
if err != nil {
return nil, err
}
if bid == kbfsmd.NullBranchID {
return nil, nil
}
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
return tlfStorage.getRange(ctx, session.UID, bid, start, stop)
} | go | func (md *MDServerDisk) GetRange(ctx context.Context, id tlf.ID,
bid kbfsmd.BranchID, mStatus kbfsmd.MergeStatus, start, stop kbfsmd.Revision,
_ *keybase1.LockID) ([]*RootMetadataSigned, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
md.log.CDebugf(ctx, "GetRange %d %d (%s)", start, stop, mStatus)
// Lookup the branch ID if not supplied
if mStatus == kbfsmd.Unmerged && bid == kbfsmd.NullBranchID {
var err error
bid, err = md.getBranchID(ctx, id)
if err != nil {
return nil, err
}
if bid == kbfsmd.NullBranchID {
return nil, nil
}
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return nil, kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(id)
if err != nil {
return nil, err
}
return tlfStorage.getRange(ctx, session.UID, bid, start, stop)
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"GetRange",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"tlf",
".",
"ID",
",",
"bid",
"kbfsmd",
".",
"BranchID",
",",
"mStatus",
"kbfsmd",
".",
"MergeStatus",
",",
"start",
",",
"stop",
"kbfsmd",
".",
"Revision",
",",
"_",
"*",
"keybase1",
".",
"LockID",
")",
"(",
"[",
"]",
"*",
"RootMetadataSigned",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"md",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"start",
",",
"stop",
",",
"mStatus",
")",
"\n\n",
"// Lookup the branch ID if not supplied",
"if",
"mStatus",
"==",
"kbfsmd",
".",
"Unmerged",
"&&",
"bid",
"==",
"kbfsmd",
".",
"NullBranchID",
"{",
"var",
"err",
"error",
"\n",
"bid",
",",
"err",
"=",
"md",
".",
"getBranchID",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"bid",
"==",
"kbfsmd",
".",
"NullBranchID",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"md",
".",
"config",
".",
"currentSessionGetter",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"tlfStorage",
",",
"err",
":=",
"md",
".",
"getStorage",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"tlfStorage",
".",
"getRange",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"bid",
",",
"start",
",",
"stop",
")",
"\n",
"}"
] | // GetRange implements the MDServer interface for MDServerDisk. | [
"GetRange",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L434-L466 |
159,013 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | Put | func (md *MDServerDisk) Put(ctx context.Context, rmds *RootMetadataSigned,
extra kbfsmd.ExtraMetadata, _ *keybase1.LockContext, _ keybase1.MDPriority) error {
if err := checkContext(ctx); err != nil {
return err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(rmds.MD.TlfID())
if err != nil {
return err
}
recordBranchID, err := tlfStorage.put(
ctx, session.UID, session.VerifyingKey, rmds, extra)
if err != nil {
return err
}
// Record branch ID
if recordBranchID {
err = md.putBranchID(ctx, rmds.MD.TlfID(), rmds.MD.BID())
if err != nil {
return kbfsmd.ServerError{Err: err}
}
}
mStatus := rmds.MD.MergedStatus()
if mStatus == kbfsmd.Merged &&
// Don't send notifies if it's just a rekey (the real mdserver
// sends a "folder needs rekey" notification in this case).
!(rmds.MD.IsRekeySet() && rmds.MD.IsWriterMetadataCopiedSet()) {
md.updateManager.setHead(rmds.MD.TlfID(), md)
}
return nil
} | go | func (md *MDServerDisk) Put(ctx context.Context, rmds *RootMetadataSigned,
extra kbfsmd.ExtraMetadata, _ *keybase1.LockContext, _ keybase1.MDPriority) error {
if err := checkContext(ctx); err != nil {
return err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return kbfsmd.ServerError{Err: err}
}
tlfStorage, err := md.getStorage(rmds.MD.TlfID())
if err != nil {
return err
}
recordBranchID, err := tlfStorage.put(
ctx, session.UID, session.VerifyingKey, rmds, extra)
if err != nil {
return err
}
// Record branch ID
if recordBranchID {
err = md.putBranchID(ctx, rmds.MD.TlfID(), rmds.MD.BID())
if err != nil {
return kbfsmd.ServerError{Err: err}
}
}
mStatus := rmds.MD.MergedStatus()
if mStatus == kbfsmd.Merged &&
// Don't send notifies if it's just a rekey (the real mdserver
// sends a "folder needs rekey" notification in this case).
!(rmds.MD.IsRekeySet() && rmds.MD.IsWriterMetadataCopiedSet()) {
md.updateManager.setHead(rmds.MD.TlfID(), md)
}
return nil
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"Put",
"(",
"ctx",
"context",
".",
"Context",
",",
"rmds",
"*",
"RootMetadataSigned",
",",
"extra",
"kbfsmd",
".",
"ExtraMetadata",
",",
"_",
"*",
"keybase1",
".",
"LockContext",
",",
"_",
"keybase1",
".",
"MDPriority",
")",
"error",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"md",
".",
"config",
".",
"currentSessionGetter",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"tlfStorage",
",",
"err",
":=",
"md",
".",
"getStorage",
"(",
"rmds",
".",
"MD",
".",
"TlfID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"recordBranchID",
",",
"err",
":=",
"tlfStorage",
".",
"put",
"(",
"ctx",
",",
"session",
".",
"UID",
",",
"session",
".",
"VerifyingKey",
",",
"rmds",
",",
"extra",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Record branch ID",
"if",
"recordBranchID",
"{",
"err",
"=",
"md",
".",
"putBranchID",
"(",
"ctx",
",",
"rmds",
".",
"MD",
".",
"TlfID",
"(",
")",
",",
"rmds",
".",
"MD",
".",
"BID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"mStatus",
":=",
"rmds",
".",
"MD",
".",
"MergedStatus",
"(",
")",
"\n",
"if",
"mStatus",
"==",
"kbfsmd",
".",
"Merged",
"&&",
"// Don't send notifies if it's just a rekey (the real mdserver",
"// sends a \"folder needs rekey\" notification in this case).",
"!",
"(",
"rmds",
".",
"MD",
".",
"IsRekeySet",
"(",
")",
"&&",
"rmds",
".",
"MD",
".",
"IsWriterMetadataCopiedSet",
"(",
")",
")",
"{",
"md",
".",
"updateManager",
".",
"setHead",
"(",
"rmds",
".",
"MD",
".",
"TlfID",
"(",
")",
",",
"md",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Put implements the MDServer interface for MDServerDisk. | [
"Put",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L469-L508 |
159,014 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | PruneBranch | func (md *MDServerDisk) PruneBranch(ctx context.Context, id tlf.ID, bid kbfsmd.BranchID) error {
if err := checkContext(ctx); err != nil {
return err
}
if bid == kbfsmd.NullBranchID {
return kbfsmd.ServerErrorBadRequest{Reason: "Invalid branch ID"}
}
currBID, err := md.getBranchID(ctx, id)
if err != nil {
return err
}
if currBID == kbfsmd.NullBranchID || bid != currBID {
return kbfsmd.ServerErrorBadRequest{Reason: "Invalid branch ID"}
}
// Don't actually delete unmerged history. This is intentional
// to be consistent with the mdserver behavior-- it garbage
// collects discarded branches in the background.
return md.deleteBranchID(ctx, id)
} | go | func (md *MDServerDisk) PruneBranch(ctx context.Context, id tlf.ID, bid kbfsmd.BranchID) error {
if err := checkContext(ctx); err != nil {
return err
}
if bid == kbfsmd.NullBranchID {
return kbfsmd.ServerErrorBadRequest{Reason: "Invalid branch ID"}
}
currBID, err := md.getBranchID(ctx, id)
if err != nil {
return err
}
if currBID == kbfsmd.NullBranchID || bid != currBID {
return kbfsmd.ServerErrorBadRequest{Reason: "Invalid branch ID"}
}
// Don't actually delete unmerged history. This is intentional
// to be consistent with the mdserver behavior-- it garbage
// collects discarded branches in the background.
return md.deleteBranchID(ctx, id)
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"PruneBranch",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"tlf",
".",
"ID",
",",
"bid",
"kbfsmd",
".",
"BranchID",
")",
"error",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"bid",
"==",
"kbfsmd",
".",
"NullBranchID",
"{",
"return",
"kbfsmd",
".",
"ServerErrorBadRequest",
"{",
"Reason",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"currBID",
",",
"err",
":=",
"md",
".",
"getBranchID",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"currBID",
"==",
"kbfsmd",
".",
"NullBranchID",
"||",
"bid",
"!=",
"currBID",
"{",
"return",
"kbfsmd",
".",
"ServerErrorBadRequest",
"{",
"Reason",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"// Don't actually delete unmerged history. This is intentional",
"// to be consistent with the mdserver behavior-- it garbage",
"// collects discarded branches in the background.",
"return",
"md",
".",
"deleteBranchID",
"(",
"ctx",
",",
"id",
")",
"\n",
"}"
] | // PruneBranch implements the MDServer interface for MDServerDisk. | [
"PruneBranch",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L529-L550 |
159,015 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | TruncateUnlock | func (md *MDServerDisk) TruncateUnlock(ctx context.Context, id tlf.ID) (
bool, error) {
if err := checkContext(ctx); err != nil {
return false, err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return false, kbfsmd.ServerError{Err: err}
}
md.lock.Lock()
defer md.lock.Unlock()
err = md.checkShutdownLocked()
if err != nil {
return false, err
}
return md.truncateLockManager.truncateUnlock(session.CryptPublicKey, id)
} | go | func (md *MDServerDisk) TruncateUnlock(ctx context.Context, id tlf.ID) (
bool, error) {
if err := checkContext(ctx); err != nil {
return false, err
}
session, err := md.config.currentSessionGetter().GetCurrentSession(ctx)
if err != nil {
return false, kbfsmd.ServerError{Err: err}
}
md.lock.Lock()
defer md.lock.Unlock()
err = md.checkShutdownLocked()
if err != nil {
return false, err
}
return md.truncateLockManager.truncateUnlock(session.CryptPublicKey, id)
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"TruncateUnlock",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"tlf",
".",
"ID",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"md",
".",
"config",
".",
"currentSessionGetter",
"(",
")",
".",
"GetCurrentSession",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"kbfsmd",
".",
"ServerError",
"{",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"md",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"md",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"err",
"=",
"md",
".",
"checkShutdownLocked",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"md",
".",
"truncateLockManager",
".",
"truncateUnlock",
"(",
"session",
".",
"CryptPublicKey",
",",
"id",
")",
"\n",
"}"
] | // TruncateUnlock implements the MDServer interface for MDServerDisk. | [
"TruncateUnlock",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L610-L629 |
159,016 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | Shutdown | func (md *MDServerDisk) Shutdown() {
md.lock.Lock()
defer md.lock.Unlock()
if md.handleDb == nil {
return
}
// Make further accesses error out.
md.handleDb.Close()
md.handleDb = nil
md.branchDb.Close()
md.branchDb = nil
tlfStorage := md.tlfStorage
md.tlfStorage = nil
for _, s := range tlfStorage {
s.shutdown()
}
if md.shutdownFunc != nil {
md.shutdownFunc(md.log)
}
} | go | func (md *MDServerDisk) Shutdown() {
md.lock.Lock()
defer md.lock.Unlock()
if md.handleDb == nil {
return
}
// Make further accesses error out.
md.handleDb.Close()
md.handleDb = nil
md.branchDb.Close()
md.branchDb = nil
tlfStorage := md.tlfStorage
md.tlfStorage = nil
for _, s := range tlfStorage {
s.shutdown()
}
if md.shutdownFunc != nil {
md.shutdownFunc(md.log)
}
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"Shutdown",
"(",
")",
"{",
"md",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"md",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"md",
".",
"handleDb",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// Make further accesses error out.",
"md",
".",
"handleDb",
".",
"Close",
"(",
")",
"\n",
"md",
".",
"handleDb",
"=",
"nil",
"\n\n",
"md",
".",
"branchDb",
".",
"Close",
"(",
")",
"\n",
"md",
".",
"branchDb",
"=",
"nil",
"\n\n",
"tlfStorage",
":=",
"md",
".",
"tlfStorage",
"\n",
"md",
".",
"tlfStorage",
"=",
"nil",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"tlfStorage",
"{",
"s",
".",
"shutdown",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"md",
".",
"shutdownFunc",
"!=",
"nil",
"{",
"md",
".",
"shutdownFunc",
"(",
"md",
".",
"log",
")",
"\n",
"}",
"\n",
"}"
] | // Shutdown implements the MDServer interface for MDServerDisk. | [
"Shutdown",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L632-L657 |
159,017 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | GetKeyBundles | func (md *MDServerDisk) GetKeyBundles(ctx context.Context,
tlfID tlf.ID, wkbID kbfsmd.TLFWriterKeyBundleID, rkbID kbfsmd.TLFReaderKeyBundleID) (
*kbfsmd.TLFWriterKeyBundleV3, *kbfsmd.TLFReaderKeyBundleV3, error) {
if err := checkContext(ctx); err != nil {
return nil, nil, err
}
tlfStorage, err := md.getStorage(tlfID)
if err != nil {
return nil, nil, err
}
return tlfStorage.getKeyBundles(tlfID, wkbID, rkbID)
} | go | func (md *MDServerDisk) GetKeyBundles(ctx context.Context,
tlfID tlf.ID, wkbID kbfsmd.TLFWriterKeyBundleID, rkbID kbfsmd.TLFReaderKeyBundleID) (
*kbfsmd.TLFWriterKeyBundleV3, *kbfsmd.TLFReaderKeyBundleV3, error) {
if err := checkContext(ctx); err != nil {
return nil, nil, err
}
tlfStorage, err := md.getStorage(tlfID)
if err != nil {
return nil, nil, err
}
return tlfStorage.getKeyBundles(tlfID, wkbID, rkbID)
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"GetKeyBundles",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"wkbID",
"kbfsmd",
".",
"TLFWriterKeyBundleID",
",",
"rkbID",
"kbfsmd",
".",
"TLFReaderKeyBundleID",
")",
"(",
"*",
"kbfsmd",
".",
"TLFWriterKeyBundleV3",
",",
"*",
"kbfsmd",
".",
"TLFReaderKeyBundleV3",
",",
"error",
")",
"{",
"if",
"err",
":=",
"checkContext",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tlfStorage",
",",
"err",
":=",
"md",
".",
"getStorage",
"(",
"tlfID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"tlfStorage",
".",
"getKeyBundles",
"(",
"tlfID",
",",
"wkbID",
",",
"rkbID",
")",
"\n",
"}"
] | // GetKeyBundles implements the MDServer interface for MDServerDisk. | [
"GetKeyBundles",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L780-L793 |
159,018 | keybase/client | go/kbfs/libkbfs/mdserver_disk.go | FindNextMD | func (md *MDServerDisk) FindNextMD(
ctx context.Context, tlfID tlf.ID, rootSeqno keybase1.Seqno) (
nextKbfsRoot *kbfsmd.MerkleRoot, nextMerkleNodes [][]byte,
nextRootSeqno keybase1.Seqno, err error) {
return nil, nil, 0, nil
} | go | func (md *MDServerDisk) FindNextMD(
ctx context.Context, tlfID tlf.ID, rootSeqno keybase1.Seqno) (
nextKbfsRoot *kbfsmd.MerkleRoot, nextMerkleNodes [][]byte,
nextRootSeqno keybase1.Seqno, err error) {
return nil, nil, 0, nil
} | [
"func",
"(",
"md",
"*",
"MDServerDisk",
")",
"FindNextMD",
"(",
"ctx",
"context",
".",
"Context",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"rootSeqno",
"keybase1",
".",
"Seqno",
")",
"(",
"nextKbfsRoot",
"*",
"kbfsmd",
".",
"MerkleRoot",
",",
"nextMerkleNodes",
"[",
"]",
"[",
"]",
"byte",
",",
"nextRootSeqno",
"keybase1",
".",
"Seqno",
",",
"err",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"0",
",",
"nil",
"\n",
"}"
] | // FindNextMD implements the MDServer interface for MDServerDisk. | [
"FindNextMD",
"implements",
"the",
"MDServer",
"interface",
"for",
"MDServerDisk",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/mdserver_disk.go#L802-L807 |
159,019 | keybase/client | go/libkb/bootstrap_active_device.go | BootstrapActiveDeviceFromConfig | func BootstrapActiveDeviceFromConfig(m MetaContext, online bool) (uid keybase1.UID, err error) {
uid, err = bootstrapActiveDeviceFromConfigReturnRawError(m, online, keybase1.UID(""))
err = fixupBootstrapError(err)
return uid, err
} | go | func BootstrapActiveDeviceFromConfig(m MetaContext, online bool) (uid keybase1.UID, err error) {
uid, err = bootstrapActiveDeviceFromConfigReturnRawError(m, online, keybase1.UID(""))
err = fixupBootstrapError(err)
return uid, err
} | [
"func",
"BootstrapActiveDeviceFromConfig",
"(",
"m",
"MetaContext",
",",
"online",
"bool",
")",
"(",
"uid",
"keybase1",
".",
"UID",
",",
"err",
"error",
")",
"{",
"uid",
",",
"err",
"=",
"bootstrapActiveDeviceFromConfigReturnRawError",
"(",
"m",
",",
"online",
",",
"keybase1",
".",
"UID",
"(",
"\"",
"\"",
")",
")",
"\n",
"err",
"=",
"fixupBootstrapError",
"(",
"err",
")",
"\n",
"return",
"uid",
",",
"err",
"\n",
"}"
] | // BootstrapActiveDeviceFromConfig takes the user's config.json, keys.mpack file and
// secret store to populate ActiveDevice, and to have all credentials necessary
// to sign NIST tokens, allowing the user to act as if "logged in". Will return
// nil if everything work, LoginRequiredError if a real "login" is required to
// make the app work, and various errors on unexpected failures. | [
"BootstrapActiveDeviceFromConfig",
"takes",
"the",
"user",
"s",
"config",
".",
"json",
"keys",
".",
"mpack",
"file",
"and",
"secret",
"store",
"to",
"populate",
"ActiveDevice",
"and",
"to",
"have",
"all",
"credentials",
"necessary",
"to",
"sign",
"NIST",
"tokens",
"allowing",
"the",
"user",
"to",
"act",
"as",
"if",
"logged",
"in",
".",
"Will",
"return",
"nil",
"if",
"everything",
"work",
"LoginRequiredError",
"if",
"a",
"real",
"login",
"is",
"required",
"to",
"make",
"the",
"app",
"work",
"and",
"various",
"errors",
"on",
"unexpected",
"failures",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/bootstrap_active_device.go#L31-L35 |
159,020 | keybase/client | go/libkb/bootstrap_active_device.go | BootstrapActiveDeviceWithMetaContext | func BootstrapActiveDeviceWithMetaContext(m MetaContext) (ok bool, uid keybase1.UID, err error) {
uid, err = BootstrapActiveDeviceFromConfig(m, true)
ok = false
if err == nil {
ok = true
} else if _, isLRE := err.(LoginRequiredError); isLRE {
err = nil
}
return ok, uid, err
} | go | func BootstrapActiveDeviceWithMetaContext(m MetaContext) (ok bool, uid keybase1.UID, err error) {
uid, err = BootstrapActiveDeviceFromConfig(m, true)
ok = false
if err == nil {
ok = true
} else if _, isLRE := err.(LoginRequiredError); isLRE {
err = nil
}
return ok, uid, err
} | [
"func",
"BootstrapActiveDeviceWithMetaContext",
"(",
"m",
"MetaContext",
")",
"(",
"ok",
"bool",
",",
"uid",
"keybase1",
".",
"UID",
",",
"err",
"error",
")",
"{",
"uid",
",",
"err",
"=",
"BootstrapActiveDeviceFromConfig",
"(",
"m",
",",
"true",
")",
"\n",
"ok",
"=",
"false",
"\n",
"if",
"err",
"==",
"nil",
"{",
"ok",
"=",
"true",
"\n",
"}",
"else",
"if",
"_",
",",
"isLRE",
":=",
"err",
".",
"(",
"LoginRequiredError",
")",
";",
"isLRE",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"ok",
",",
"uid",
",",
"err",
"\n",
"}"
] | // BootstrapActiveDeviceWithMetaContext will setup an ActiveDevice with a NIST Factory
// for the caller. The m.loginContext passed through isn't really needed
// for anything aside from assertions, but as we phase out LoginState, we'll
// leave it here so that assertions in LoginState can still pass. | [
"BootstrapActiveDeviceWithMetaContext",
"will",
"setup",
"an",
"ActiveDevice",
"with",
"a",
"NIST",
"Factory",
"for",
"the",
"caller",
".",
"The",
"m",
".",
"loginContext",
"passed",
"through",
"isn",
"t",
"really",
"needed",
"for",
"anything",
"aside",
"from",
"assertions",
"but",
"as",
"we",
"phase",
"out",
"LoginState",
"we",
"ll",
"leave",
"it",
"here",
"so",
"that",
"assertions",
"in",
"LoginState",
"can",
"still",
"pass",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/bootstrap_active_device.go#L163-L172 |
159,021 | keybase/client | go/libkb/bootstrap_active_device.go | BootstrapActiveDeviceWithMetaContextAndAssertUID | func BootstrapActiveDeviceWithMetaContextAndAssertUID(m MetaContext, uid keybase1.UID) (ok bool, err error) {
_, err = bootstrapActiveDeviceFromConfigReturnRawError(m, true, uid)
switch err.(type) {
case nil:
return true, nil
case LoginRequiredError:
return false, nil
case UIDMismatchError:
return false, nil
case NoUIDError:
return false, nil
default:
if err == ErrUnlockNotPossible {
return false, nil
}
return false, err
}
} | go | func BootstrapActiveDeviceWithMetaContextAndAssertUID(m MetaContext, uid keybase1.UID) (ok bool, err error) {
_, err = bootstrapActiveDeviceFromConfigReturnRawError(m, true, uid)
switch err.(type) {
case nil:
return true, nil
case LoginRequiredError:
return false, nil
case UIDMismatchError:
return false, nil
case NoUIDError:
return false, nil
default:
if err == ErrUnlockNotPossible {
return false, nil
}
return false, err
}
} | [
"func",
"BootstrapActiveDeviceWithMetaContextAndAssertUID",
"(",
"m",
"MetaContext",
",",
"uid",
"keybase1",
".",
"UID",
")",
"(",
"ok",
"bool",
",",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"bootstrapActiveDeviceFromConfigReturnRawError",
"(",
"m",
",",
"true",
",",
"uid",
")",
"\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"LoginRequiredError",
":",
"return",
"false",
",",
"nil",
"\n",
"case",
"UIDMismatchError",
":",
"return",
"false",
",",
"nil",
"\n",
"case",
"NoUIDError",
":",
"return",
"false",
",",
"nil",
"\n",
"default",
":",
"if",
"err",
"==",
"ErrUnlockNotPossible",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"}"
] | // BootstrapActiveDeviceWithMetaContextAndAssertUID will setup an ActiveDevice with a NIST Factory
// for the caller. It only works if we're logged in as the given UID | [
"BootstrapActiveDeviceWithMetaContextAndAssertUID",
"will",
"setup",
"an",
"ActiveDevice",
"with",
"a",
"NIST",
"Factory",
"for",
"the",
"caller",
".",
"It",
"only",
"works",
"if",
"we",
"re",
"logged",
"in",
"as",
"the",
"given",
"UID"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/bootstrap_active_device.go#L176-L193 |
159,022 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | notifyWorker | func (brq *blockRetrievalQueue) notifyWorker(priority int) {
// On-demand workers and prefetch workers share the priority queue. This
// allows maximum time for requests to jump the queue, at least until the
// worker actually begins working on it.
//
// Note that the worker being notified won't necessarily work on the exact
// request that caused the notification. It's just a counter. That means
// that sometimes on-demand workers will work on prefetch requests, and
// vice versa. But the numbers should match.
//
// However, there are some pathological scenarios where if all the workers
// of one type are making progress but the other type are not (which is
// highly improbable), requests of one type could starve the other. By
// design, on-demand requests _should_ starve prefetch requests, so this is
// a problem only if prefetch requests can starve on-demand workers. But
// because there are far more on-demand workers than prefetch workers, this
// should never actually happen.
workerCh := brq.workerCh
if priority <= throttleRequestPriority && brq.throttledWorkCh != nil {
workerCh = brq.throttledWorkCh
} else if priority < defaultOnDemandRequestPriority {
workerCh = brq.prefetchWorkerCh
}
brq.sendWork(workerCh)
} | go | func (brq *blockRetrievalQueue) notifyWorker(priority int) {
// On-demand workers and prefetch workers share the priority queue. This
// allows maximum time for requests to jump the queue, at least until the
// worker actually begins working on it.
//
// Note that the worker being notified won't necessarily work on the exact
// request that caused the notification. It's just a counter. That means
// that sometimes on-demand workers will work on prefetch requests, and
// vice versa. But the numbers should match.
//
// However, there are some pathological scenarios where if all the workers
// of one type are making progress but the other type are not (which is
// highly improbable), requests of one type could starve the other. By
// design, on-demand requests _should_ starve prefetch requests, so this is
// a problem only if prefetch requests can starve on-demand workers. But
// because there are far more on-demand workers than prefetch workers, this
// should never actually happen.
workerCh := brq.workerCh
if priority <= throttleRequestPriority && brq.throttledWorkCh != nil {
workerCh = brq.throttledWorkCh
} else if priority < defaultOnDemandRequestPriority {
workerCh = brq.prefetchWorkerCh
}
brq.sendWork(workerCh)
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"notifyWorker",
"(",
"priority",
"int",
")",
"{",
"// On-demand workers and prefetch workers share the priority queue. This",
"// allows maximum time for requests to jump the queue, at least until the",
"// worker actually begins working on it.",
"//",
"// Note that the worker being notified won't necessarily work on the exact",
"// request that caused the notification. It's just a counter. That means",
"// that sometimes on-demand workers will work on prefetch requests, and",
"// vice versa. But the numbers should match.",
"//",
"// However, there are some pathological scenarios where if all the workers",
"// of one type are making progress but the other type are not (which is",
"// highly improbable), requests of one type could starve the other. By",
"// design, on-demand requests _should_ starve prefetch requests, so this is",
"// a problem only if prefetch requests can starve on-demand workers. But",
"// because there are far more on-demand workers than prefetch workers, this",
"// should never actually happen.",
"workerCh",
":=",
"brq",
".",
"workerCh",
"\n",
"if",
"priority",
"<=",
"throttleRequestPriority",
"&&",
"brq",
".",
"throttledWorkCh",
"!=",
"nil",
"{",
"workerCh",
"=",
"brq",
".",
"throttledWorkCh",
"\n",
"}",
"else",
"if",
"priority",
"<",
"defaultOnDemandRequestPriority",
"{",
"workerCh",
"=",
"brq",
".",
"prefetchWorkerCh",
"\n",
"}",
"\n",
"brq",
".",
"sendWork",
"(",
"workerCh",
")",
"\n",
"}"
] | // notifyWorker notifies workers that there is a new request for processing. | [
"notifyWorker",
"notifies",
"workers",
"that",
"there",
"is",
"a",
"new",
"request",
"for",
"processing",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L267-L291 |
159,023 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | PutInCaches | func (brq *blockRetrievalQueue) PutInCaches(ctx context.Context,
ptr data.BlockPointer, tlfID tlf.ID, block data.Block, lifetime data.BlockCacheLifetime,
prefetchStatus PrefetchStatus, cacheType DiskBlockCacheType) (err error) {
// TODO: plumb through whether journaling is enabled for this TLF,
// to set the right cache behavior.
err = brq.config.BlockCache().Put(
ptr, tlfID, block, lifetime, data.DoCacheHash)
switch err.(type) {
case nil:
case data.CachePutCacheFullError:
// Ignore cache full errors and send to the disk cache anyway.
default:
return err
}
dbc := brq.config.DiskBlockCache()
if dbc == nil {
return brq.setPrefetchStatus(ptr.ID, prefetchStatus)
}
err = dbc.UpdateMetadata(ctx, tlfID, ptr.ID, prefetchStatus, cacheType)
switch errors.Cause(err).(type) {
case nil:
case data.NoSuchBlockError:
// TODO: Add the block to the DBC. This is complicated because we
// need the serverHalf.
brq.vlog.CLogf(ctx, libkb.VLog2,
"Block %s missing for disk block cache metadata update", ptr.ID)
default:
brq.vlog.CLogf(ctx, libkb.VLog2, "Error updating metadata: %+v", err)
}
// All disk cache errors are fatal
return err
} | go | func (brq *blockRetrievalQueue) PutInCaches(ctx context.Context,
ptr data.BlockPointer, tlfID tlf.ID, block data.Block, lifetime data.BlockCacheLifetime,
prefetchStatus PrefetchStatus, cacheType DiskBlockCacheType) (err error) {
// TODO: plumb through whether journaling is enabled for this TLF,
// to set the right cache behavior.
err = brq.config.BlockCache().Put(
ptr, tlfID, block, lifetime, data.DoCacheHash)
switch err.(type) {
case nil:
case data.CachePutCacheFullError:
// Ignore cache full errors and send to the disk cache anyway.
default:
return err
}
dbc := brq.config.DiskBlockCache()
if dbc == nil {
return brq.setPrefetchStatus(ptr.ID, prefetchStatus)
}
err = dbc.UpdateMetadata(ctx, tlfID, ptr.ID, prefetchStatus, cacheType)
switch errors.Cause(err).(type) {
case nil:
case data.NoSuchBlockError:
// TODO: Add the block to the DBC. This is complicated because we
// need the serverHalf.
brq.vlog.CLogf(ctx, libkb.VLog2,
"Block %s missing for disk block cache metadata update", ptr.ID)
default:
brq.vlog.CLogf(ctx, libkb.VLog2, "Error updating metadata: %+v", err)
}
// All disk cache errors are fatal
return err
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"PutInCaches",
"(",
"ctx",
"context",
".",
"Context",
",",
"ptr",
"data",
".",
"BlockPointer",
",",
"tlfID",
"tlf",
".",
"ID",
",",
"block",
"data",
".",
"Block",
",",
"lifetime",
"data",
".",
"BlockCacheLifetime",
",",
"prefetchStatus",
"PrefetchStatus",
",",
"cacheType",
"DiskBlockCacheType",
")",
"(",
"err",
"error",
")",
"{",
"// TODO: plumb through whether journaling is enabled for this TLF,",
"// to set the right cache behavior.",
"err",
"=",
"brq",
".",
"config",
".",
"BlockCache",
"(",
")",
".",
"Put",
"(",
"ptr",
",",
"tlfID",
",",
"block",
",",
"lifetime",
",",
"data",
".",
"DoCacheHash",
")",
"\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"case",
"data",
".",
"CachePutCacheFullError",
":",
"// Ignore cache full errors and send to the disk cache anyway.",
"default",
":",
"return",
"err",
"\n",
"}",
"\n",
"dbc",
":=",
"brq",
".",
"config",
".",
"DiskBlockCache",
"(",
")",
"\n",
"if",
"dbc",
"==",
"nil",
"{",
"return",
"brq",
".",
"setPrefetchStatus",
"(",
"ptr",
".",
"ID",
",",
"prefetchStatus",
")",
"\n",
"}",
"\n",
"err",
"=",
"dbc",
".",
"UpdateMetadata",
"(",
"ctx",
",",
"tlfID",
",",
"ptr",
".",
"ID",
",",
"prefetchStatus",
",",
"cacheType",
")",
"\n",
"switch",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"case",
"data",
".",
"NoSuchBlockError",
":",
"// TODO: Add the block to the DBC. This is complicated because we",
"// need the serverHalf.",
"brq",
".",
"vlog",
".",
"CLogf",
"(",
"ctx",
",",
"libkb",
".",
"VLog2",
",",
"\"",
"\"",
",",
"ptr",
".",
"ID",
")",
"\n",
"default",
":",
"brq",
".",
"vlog",
".",
"CLogf",
"(",
"ctx",
",",
"libkb",
".",
"VLog2",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// All disk cache errors are fatal",
"return",
"err",
"\n",
"}"
] | // PutInCaches implements the BlockRetriever interface for
// BlockRetrievalQueue. | [
"PutInCaches",
"implements",
"the",
"BlockRetriever",
"interface",
"for",
"BlockRetrievalQueue",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L348-L379 |
159,024 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | checkCaches | func (brq *blockRetrievalQueue) checkCaches(ctx context.Context,
kmd libkey.KeyMetadata, ptr data.BlockPointer, block data.Block,
action BlockRequestAction) (PrefetchStatus, error) {
dbc := brq.config.DiskBlockCache()
preferredCacheType := action.CacheType()
cachedBlock, err := brq.config.BlockCache().Get(ptr)
if err == nil {
if dbc == nil {
block.Set(cachedBlock)
return brq.getPrefetchStatus(ptr.ID)
}
prefetchStatus, err := dbc.GetPrefetchStatus(
ctx, kmd.TlfID(), ptr.ID, preferredCacheType)
if err == nil {
block.Set(cachedBlock)
return prefetchStatus, nil
}
// If the prefetch status wasn't in the preferred cache, do a
// full `Get()` below in an attempt to move the full block
// into the preferred cache.
} else if dbc == nil || action.DelayCacheCheck() {
return NoPrefetch, err
}
blockBuf, serverHalf, prefetchStatus, err := dbc.Get(
ctx, kmd.TlfID(), ptr.ID, preferredCacheType)
if err != nil {
return NoPrefetch, err
}
if len(blockBuf) == 0 {
return NoPrefetch, data.NoSuchBlockError{ID: ptr.ID}
}
// Assemble the block from the encrypted block buffer.
err = brq.config.blockGetter().assembleBlock(ctx, kmd, ptr, block, blockBuf,
serverHalf)
if err == nil {
// Cache the block in memory. TODO: plumb through whether
// journaling is enabled for this TLF, to set the right cache
// behavior.
brq.config.BlockCache().Put(
ptr, kmd.TlfID(), block, data.TransientEntry, data.DoCacheHash)
}
return prefetchStatus, err
} | go | func (brq *blockRetrievalQueue) checkCaches(ctx context.Context,
kmd libkey.KeyMetadata, ptr data.BlockPointer, block data.Block,
action BlockRequestAction) (PrefetchStatus, error) {
dbc := brq.config.DiskBlockCache()
preferredCacheType := action.CacheType()
cachedBlock, err := brq.config.BlockCache().Get(ptr)
if err == nil {
if dbc == nil {
block.Set(cachedBlock)
return brq.getPrefetchStatus(ptr.ID)
}
prefetchStatus, err := dbc.GetPrefetchStatus(
ctx, kmd.TlfID(), ptr.ID, preferredCacheType)
if err == nil {
block.Set(cachedBlock)
return prefetchStatus, nil
}
// If the prefetch status wasn't in the preferred cache, do a
// full `Get()` below in an attempt to move the full block
// into the preferred cache.
} else if dbc == nil || action.DelayCacheCheck() {
return NoPrefetch, err
}
blockBuf, serverHalf, prefetchStatus, err := dbc.Get(
ctx, kmd.TlfID(), ptr.ID, preferredCacheType)
if err != nil {
return NoPrefetch, err
}
if len(blockBuf) == 0 {
return NoPrefetch, data.NoSuchBlockError{ID: ptr.ID}
}
// Assemble the block from the encrypted block buffer.
err = brq.config.blockGetter().assembleBlock(ctx, kmd, ptr, block, blockBuf,
serverHalf)
if err == nil {
// Cache the block in memory. TODO: plumb through whether
// journaling is enabled for this TLF, to set the right cache
// behavior.
brq.config.BlockCache().Put(
ptr, kmd.TlfID(), block, data.TransientEntry, data.DoCacheHash)
}
return prefetchStatus, err
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"checkCaches",
"(",
"ctx",
"context",
".",
"Context",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
",",
"ptr",
"data",
".",
"BlockPointer",
",",
"block",
"data",
".",
"Block",
",",
"action",
"BlockRequestAction",
")",
"(",
"PrefetchStatus",
",",
"error",
")",
"{",
"dbc",
":=",
"brq",
".",
"config",
".",
"DiskBlockCache",
"(",
")",
"\n",
"preferredCacheType",
":=",
"action",
".",
"CacheType",
"(",
")",
"\n\n",
"cachedBlock",
",",
"err",
":=",
"brq",
".",
"config",
".",
"BlockCache",
"(",
")",
".",
"Get",
"(",
"ptr",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"dbc",
"==",
"nil",
"{",
"block",
".",
"Set",
"(",
"cachedBlock",
")",
"\n",
"return",
"brq",
".",
"getPrefetchStatus",
"(",
"ptr",
".",
"ID",
")",
"\n",
"}",
"\n\n",
"prefetchStatus",
",",
"err",
":=",
"dbc",
".",
"GetPrefetchStatus",
"(",
"ctx",
",",
"kmd",
".",
"TlfID",
"(",
")",
",",
"ptr",
".",
"ID",
",",
"preferredCacheType",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"block",
".",
"Set",
"(",
"cachedBlock",
")",
"\n",
"return",
"prefetchStatus",
",",
"nil",
"\n",
"}",
"\n",
"// If the prefetch status wasn't in the preferred cache, do a",
"// full `Get()` below in an attempt to move the full block",
"// into the preferred cache.",
"}",
"else",
"if",
"dbc",
"==",
"nil",
"||",
"action",
".",
"DelayCacheCheck",
"(",
")",
"{",
"return",
"NoPrefetch",
",",
"err",
"\n",
"}",
"\n\n",
"blockBuf",
",",
"serverHalf",
",",
"prefetchStatus",
",",
"err",
":=",
"dbc",
".",
"Get",
"(",
"ctx",
",",
"kmd",
".",
"TlfID",
"(",
")",
",",
"ptr",
".",
"ID",
",",
"preferredCacheType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"NoPrefetch",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"blockBuf",
")",
"==",
"0",
"{",
"return",
"NoPrefetch",
",",
"data",
".",
"NoSuchBlockError",
"{",
"ID",
":",
"ptr",
".",
"ID",
"}",
"\n",
"}",
"\n\n",
"// Assemble the block from the encrypted block buffer.",
"err",
"=",
"brq",
".",
"config",
".",
"blockGetter",
"(",
")",
".",
"assembleBlock",
"(",
"ctx",
",",
"kmd",
",",
"ptr",
",",
"block",
",",
"blockBuf",
",",
"serverHalf",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"// Cache the block in memory. TODO: plumb through whether",
"// journaling is enabled for this TLF, to set the right cache",
"// behavior.",
"brq",
".",
"config",
".",
"BlockCache",
"(",
")",
".",
"Put",
"(",
"ptr",
",",
"kmd",
".",
"TlfID",
"(",
")",
",",
"block",
",",
"data",
".",
"TransientEntry",
",",
"data",
".",
"DoCacheHash",
")",
"\n",
"}",
"\n",
"return",
"prefetchStatus",
",",
"err",
"\n",
"}"
] | // checkCaches copies a block into `block` if it's in one of our caches. | [
"checkCaches",
"copies",
"a",
"block",
"into",
"block",
"if",
"it",
"s",
"in",
"one",
"of",
"our",
"caches",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L382-L428 |
159,025 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | Request | func (brq *blockRetrievalQueue) Request(ctx context.Context,
priority int, kmd libkey.KeyMetadata, ptr data.BlockPointer, block data.Block,
lifetime data.BlockCacheLifetime, action BlockRequestAction) <-chan error {
if brq.config.IsSyncedTlf(kmd.TlfID()) {
action = action.AddSync()
}
return brq.request(ctx, priority, kmd, ptr, block, lifetime, action)
} | go | func (brq *blockRetrievalQueue) Request(ctx context.Context,
priority int, kmd libkey.KeyMetadata, ptr data.BlockPointer, block data.Block,
lifetime data.BlockCacheLifetime, action BlockRequestAction) <-chan error {
if brq.config.IsSyncedTlf(kmd.TlfID()) {
action = action.AddSync()
}
return brq.request(ctx, priority, kmd, ptr, block, lifetime, action)
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"Request",
"(",
"ctx",
"context",
".",
"Context",
",",
"priority",
"int",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
",",
"ptr",
"data",
".",
"BlockPointer",
",",
"block",
"data",
".",
"Block",
",",
"lifetime",
"data",
".",
"BlockCacheLifetime",
",",
"action",
"BlockRequestAction",
")",
"<-",
"chan",
"error",
"{",
"if",
"brq",
".",
"config",
".",
"IsSyncedTlf",
"(",
"kmd",
".",
"TlfID",
"(",
")",
")",
"{",
"action",
"=",
"action",
".",
"AddSync",
"(",
")",
"\n",
"}",
"\n",
"return",
"brq",
".",
"request",
"(",
"ctx",
",",
"priority",
",",
"kmd",
",",
"ptr",
",",
"block",
",",
"lifetime",
",",
"action",
")",
"\n",
"}"
] | // Request implements the BlockRetriever interface for blockRetrievalQueue. | [
"Request",
"implements",
"the",
"BlockRetriever",
"interface",
"for",
"blockRetrievalQueue",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L570-L577 |
159,026 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | FinalizeRequest | func (brq *blockRetrievalQueue) FinalizeRequest(
retrieval *blockRetrieval, block data.Block, cacheType DiskBlockCacheType,
retrievalErr error) {
brq.mtx.Lock()
// This might have already been removed if the context has been canceled.
// That's okay, because this will then be a no-op.
bpLookup := blockPtrLookup{retrieval.blockPtr, reflect.TypeOf(block)}
delete(brq.ptrs, bpLookup)
brq.mtx.Unlock()
brq.finalizeRequestAfterPtrDeletion(
retrieval, block, cacheType, retrievalErr)
} | go | func (brq *blockRetrievalQueue) FinalizeRequest(
retrieval *blockRetrieval, block data.Block, cacheType DiskBlockCacheType,
retrievalErr error) {
brq.mtx.Lock()
// This might have already been removed if the context has been canceled.
// That's okay, because this will then be a no-op.
bpLookup := blockPtrLookup{retrieval.blockPtr, reflect.TypeOf(block)}
delete(brq.ptrs, bpLookup)
brq.mtx.Unlock()
brq.finalizeRequestAfterPtrDeletion(
retrieval, block, cacheType, retrievalErr)
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"FinalizeRequest",
"(",
"retrieval",
"*",
"blockRetrieval",
",",
"block",
"data",
".",
"Block",
",",
"cacheType",
"DiskBlockCacheType",
",",
"retrievalErr",
"error",
")",
"{",
"brq",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"// This might have already been removed if the context has been canceled.",
"// That's okay, because this will then be a no-op.",
"bpLookup",
":=",
"blockPtrLookup",
"{",
"retrieval",
".",
"blockPtr",
",",
"reflect",
".",
"TypeOf",
"(",
"block",
")",
"}",
"\n",
"delete",
"(",
"brq",
".",
"ptrs",
",",
"bpLookup",
")",
"\n",
"brq",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n",
"brq",
".",
"finalizeRequestAfterPtrDeletion",
"(",
"retrieval",
",",
"block",
",",
"cacheType",
",",
"retrievalErr",
")",
"\n",
"}"
] | // FinalizeRequest is the last step of a retrieval request once a block has
// been obtained. It removes the request from the blockRetrievalQueue,
// preventing more requests from mutating the retrieval, then notifies all
// subscribed requests. | [
"FinalizeRequest",
"is",
"the",
"last",
"step",
"of",
"a",
"retrieval",
"request",
"once",
"a",
"block",
"has",
"been",
"obtained",
".",
"It",
"removes",
"the",
"request",
"from",
"the",
"blockRetrievalQueue",
"preventing",
"more",
"requests",
"from",
"mutating",
"the",
"retrieval",
"then",
"notifies",
"all",
"subscribed",
"requests",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L660-L671 |
159,027 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | Shutdown | func (brq *blockRetrievalQueue) Shutdown() <-chan struct{} {
brq.doneLock.Lock()
defer brq.doneLock.Unlock()
select {
case <-brq.doneCh:
return brq.shutdownCompleteCh
default:
}
var shutdownWaitGroup sync.WaitGroup
// We close `doneCh` first so that new requests coming in get
// finalized immediately rather than racing with dying workers.
close(brq.doneCh)
for _, w := range brq.workers {
channelToWaitGroup(&shutdownWaitGroup, w.Shutdown())
}
brq.finalizeAllRequests()
brq.prefetchMtx.Lock()
defer brq.prefetchMtx.Unlock()
channelToWaitGroup(&shutdownWaitGroup, brq.prefetcher.Shutdown())
brq.workerCh.Close()
brq.prefetchWorkerCh.Close()
if brq.throttledWorkCh != nil {
brq.throttledWorkCh.Close()
}
go func() {
shutdownWaitGroup.Wait()
close(brq.shutdownCompleteCh)
}()
return brq.shutdownCompleteCh
} | go | func (brq *blockRetrievalQueue) Shutdown() <-chan struct{} {
brq.doneLock.Lock()
defer brq.doneLock.Unlock()
select {
case <-brq.doneCh:
return brq.shutdownCompleteCh
default:
}
var shutdownWaitGroup sync.WaitGroup
// We close `doneCh` first so that new requests coming in get
// finalized immediately rather than racing with dying workers.
close(brq.doneCh)
for _, w := range brq.workers {
channelToWaitGroup(&shutdownWaitGroup, w.Shutdown())
}
brq.finalizeAllRequests()
brq.prefetchMtx.Lock()
defer brq.prefetchMtx.Unlock()
channelToWaitGroup(&shutdownWaitGroup, brq.prefetcher.Shutdown())
brq.workerCh.Close()
brq.prefetchWorkerCh.Close()
if brq.throttledWorkCh != nil {
brq.throttledWorkCh.Close()
}
go func() {
shutdownWaitGroup.Wait()
close(brq.shutdownCompleteCh)
}()
return brq.shutdownCompleteCh
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"Shutdown",
"(",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"brq",
".",
"doneLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"brq",
".",
"doneLock",
".",
"Unlock",
"(",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"brq",
".",
"doneCh",
":",
"return",
"brq",
".",
"shutdownCompleteCh",
"\n",
"default",
":",
"}",
"\n\n",
"var",
"shutdownWaitGroup",
"sync",
".",
"WaitGroup",
"\n",
"// We close `doneCh` first so that new requests coming in get",
"// finalized immediately rather than racing with dying workers.",
"close",
"(",
"brq",
".",
"doneCh",
")",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"brq",
".",
"workers",
"{",
"channelToWaitGroup",
"(",
"&",
"shutdownWaitGroup",
",",
"w",
".",
"Shutdown",
"(",
")",
")",
"\n",
"}",
"\n",
"brq",
".",
"finalizeAllRequests",
"(",
")",
"\n\n",
"brq",
".",
"prefetchMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"brq",
".",
"prefetchMtx",
".",
"Unlock",
"(",
")",
"\n",
"channelToWaitGroup",
"(",
"&",
"shutdownWaitGroup",
",",
"brq",
".",
"prefetcher",
".",
"Shutdown",
"(",
")",
")",
"\n\n",
"brq",
".",
"workerCh",
".",
"Close",
"(",
")",
"\n",
"brq",
".",
"prefetchWorkerCh",
".",
"Close",
"(",
")",
"\n",
"if",
"brq",
".",
"throttledWorkCh",
"!=",
"nil",
"{",
"brq",
".",
"throttledWorkCh",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"shutdownWaitGroup",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"brq",
".",
"shutdownCompleteCh",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"brq",
".",
"shutdownCompleteCh",
"\n",
"}"
] | // Shutdown is called when we are no longer accepting requests. | [
"Shutdown",
"is",
"called",
"when",
"we",
"are",
"no",
"longer",
"accepting",
"requests",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L689-L723 |
159,028 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | TogglePrefetcher | func (brq *blockRetrievalQueue) TogglePrefetcher(enable bool,
testSyncCh <-chan struct{}, testDoneCh chan<- struct{}) <-chan struct{} {
// We must hold this lock for the whole function so that multiple calls to
// this function doesn't leak prefetchers.
brq.prefetchMtx.Lock()
defer brq.prefetchMtx.Unlock()
// Allow the caller to block on the current shutdown.
ch := brq.prefetcher.Shutdown()
if enable {
brq.prefetcher = newBlockPrefetcher(
brq, brq.config, testSyncCh, testDoneCh)
}
return ch
} | go | func (brq *blockRetrievalQueue) TogglePrefetcher(enable bool,
testSyncCh <-chan struct{}, testDoneCh chan<- struct{}) <-chan struct{} {
// We must hold this lock for the whole function so that multiple calls to
// this function doesn't leak prefetchers.
brq.prefetchMtx.Lock()
defer brq.prefetchMtx.Unlock()
// Allow the caller to block on the current shutdown.
ch := brq.prefetcher.Shutdown()
if enable {
brq.prefetcher = newBlockPrefetcher(
brq, brq.config, testSyncCh, testDoneCh)
}
return ch
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"TogglePrefetcher",
"(",
"enable",
"bool",
",",
"testSyncCh",
"<-",
"chan",
"struct",
"{",
"}",
",",
"testDoneCh",
"chan",
"<-",
"struct",
"{",
"}",
")",
"<-",
"chan",
"struct",
"{",
"}",
"{",
"// We must hold this lock for the whole function so that multiple calls to",
"// this function doesn't leak prefetchers.",
"brq",
".",
"prefetchMtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"brq",
".",
"prefetchMtx",
".",
"Unlock",
"(",
")",
"\n",
"// Allow the caller to block on the current shutdown.",
"ch",
":=",
"brq",
".",
"prefetcher",
".",
"Shutdown",
"(",
")",
"\n",
"if",
"enable",
"{",
"brq",
".",
"prefetcher",
"=",
"newBlockPrefetcher",
"(",
"brq",
",",
"brq",
".",
"config",
",",
"testSyncCh",
",",
"testDoneCh",
")",
"\n",
"}",
"\n",
"return",
"ch",
"\n",
"}"
] | // TogglePrefetcher allows upstream components to turn the prefetcher on or
// off. If an error is returned due to a context cancelation, the prefetcher is
// never re-enabled. | [
"TogglePrefetcher",
"allows",
"upstream",
"components",
"to",
"turn",
"the",
"prefetcher",
"on",
"or",
"off",
".",
"If",
"an",
"error",
"is",
"returned",
"due",
"to",
"a",
"context",
"cancelation",
"the",
"prefetcher",
"is",
"never",
"re",
"-",
"enabled",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L728-L741 |
159,029 | keybase/client | go/kbfs/libkbfs/block_retrieval_queue.go | Prefetcher | func (brq *blockRetrievalQueue) Prefetcher() Prefetcher {
brq.prefetchMtx.RLock()
defer brq.prefetchMtx.RUnlock()
return brq.prefetcher
} | go | func (brq *blockRetrievalQueue) Prefetcher() Prefetcher {
brq.prefetchMtx.RLock()
defer brq.prefetchMtx.RUnlock()
return brq.prefetcher
} | [
"func",
"(",
"brq",
"*",
"blockRetrievalQueue",
")",
"Prefetcher",
"(",
")",
"Prefetcher",
"{",
"brq",
".",
"prefetchMtx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"brq",
".",
"prefetchMtx",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"brq",
".",
"prefetcher",
"\n",
"}"
] | // Prefetcher allows us to retrieve the prefetcher. | [
"Prefetcher",
"allows",
"us",
"to",
"retrieve",
"the",
"prefetcher",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/block_retrieval_queue.go#L744-L748 |
159,030 | keybase/client | go/offline/rpc_cache.go | Serve | func (c *RPCCache) Serve(mctx libkb.MetaContext, oa keybase1.OfflineAvailability, version Version, rpcName string, encrypted bool, arg interface{}, resPtr interface{},
handler func(mctx libkb.MetaContext) (interface{}, error)) (res interface{}, err error) {
if oa != keybase1.OfflineAvailability_BEST_EFFORT {
return handler(mctx)
}
mctx = mctx.WithLogTag("OFLN")
defer mctx.Trace(fmt.Sprintf("RPCCache#Serve(%d, %s, %v, %+v)", version, rpcName, encrypted, arg), func() error { return err })()
found, err := c.get(mctx, version, rpcName, encrypted, arg, resPtr)
if err != nil {
return nil, err
}
// If we know we're not connected, use the cache value right away.
// TODO: API calls shouldn't necessarily depend on the
// connectivity as measured by gregor.
if mctx.G().ConnectivityMonitor.IsConnected(mctx.Ctx()) == libkb.ConnectivityMonitorNo {
if !found {
return nil, libkb.OfflineError{}
}
return nil, nil // resPtr was filled in by get()
}
type handlerRes struct {
res interface{}
err error
}
resCh := make(chan handlerRes, 1)
// New goroutine needs a new metacontext, in case the original
// gets canceled after the timeout below. Preserve the log tags
// though.
newMctx := mctx.BackgroundWithLogTags()
// Launch a background goroutine to try to invoke the handler.
// Even if we hit a timeout below and return the cached value,
// this goroutine will keep going in an attempt to populate the
// cache on a slow network.
go func() {
res, err := handler(newMctx)
if err != nil {
resCh <- handlerRes{res, err}
return
}
tmp := c.put(newMctx, version, rpcName, encrypted, arg, res)
if tmp != nil {
newMctx.Warning("Error putting RPC to offline storage: %s", tmp.Error())
}
resCh <- handlerRes{res, nil}
}()
var timerCh <-chan time.Time
if found {
// Use a quick timeout if there's an available cached value.
timerCh = mctx.G().Clock().After(bestEffortHandlerTimeout)
} else {
// Wait indefinitely on the handler if there's nothing in the cache.
timerCh = make(chan time.Time)
}
select {
case hr := <-resCh:
// Explicitly return hr.res rather than nil in the err != nil
// case, because some RPCs might depend on getting a result
// along with an error.
return hr.res, hr.err
case <-timerCh:
mctx.Debug("Timeout waiting for handler; using cached value instead")
return res, nil
case <-mctx.Ctx().Done():
return nil, mctx.Ctx().Err()
}
} | go | func (c *RPCCache) Serve(mctx libkb.MetaContext, oa keybase1.OfflineAvailability, version Version, rpcName string, encrypted bool, arg interface{}, resPtr interface{},
handler func(mctx libkb.MetaContext) (interface{}, error)) (res interface{}, err error) {
if oa != keybase1.OfflineAvailability_BEST_EFFORT {
return handler(mctx)
}
mctx = mctx.WithLogTag("OFLN")
defer mctx.Trace(fmt.Sprintf("RPCCache#Serve(%d, %s, %v, %+v)", version, rpcName, encrypted, arg), func() error { return err })()
found, err := c.get(mctx, version, rpcName, encrypted, arg, resPtr)
if err != nil {
return nil, err
}
// If we know we're not connected, use the cache value right away.
// TODO: API calls shouldn't necessarily depend on the
// connectivity as measured by gregor.
if mctx.G().ConnectivityMonitor.IsConnected(mctx.Ctx()) == libkb.ConnectivityMonitorNo {
if !found {
return nil, libkb.OfflineError{}
}
return nil, nil // resPtr was filled in by get()
}
type handlerRes struct {
res interface{}
err error
}
resCh := make(chan handlerRes, 1)
// New goroutine needs a new metacontext, in case the original
// gets canceled after the timeout below. Preserve the log tags
// though.
newMctx := mctx.BackgroundWithLogTags()
// Launch a background goroutine to try to invoke the handler.
// Even if we hit a timeout below and return the cached value,
// this goroutine will keep going in an attempt to populate the
// cache on a slow network.
go func() {
res, err := handler(newMctx)
if err != nil {
resCh <- handlerRes{res, err}
return
}
tmp := c.put(newMctx, version, rpcName, encrypted, arg, res)
if tmp != nil {
newMctx.Warning("Error putting RPC to offline storage: %s", tmp.Error())
}
resCh <- handlerRes{res, nil}
}()
var timerCh <-chan time.Time
if found {
// Use a quick timeout if there's an available cached value.
timerCh = mctx.G().Clock().After(bestEffortHandlerTimeout)
} else {
// Wait indefinitely on the handler if there's nothing in the cache.
timerCh = make(chan time.Time)
}
select {
case hr := <-resCh:
// Explicitly return hr.res rather than nil in the err != nil
// case, because some RPCs might depend on getting a result
// along with an error.
return hr.res, hr.err
case <-timerCh:
mctx.Debug("Timeout waiting for handler; using cached value instead")
return res, nil
case <-mctx.Ctx().Done():
return nil, mctx.Ctx().Err()
}
} | [
"func",
"(",
"c",
"*",
"RPCCache",
")",
"Serve",
"(",
"mctx",
"libkb",
".",
"MetaContext",
",",
"oa",
"keybase1",
".",
"OfflineAvailability",
",",
"version",
"Version",
",",
"rpcName",
"string",
",",
"encrypted",
"bool",
",",
"arg",
"interface",
"{",
"}",
",",
"resPtr",
"interface",
"{",
"}",
",",
"handler",
"func",
"(",
"mctx",
"libkb",
".",
"MetaContext",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"(",
"res",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"if",
"oa",
"!=",
"keybase1",
".",
"OfflineAvailability_BEST_EFFORT",
"{",
"return",
"handler",
"(",
"mctx",
")",
"\n",
"}",
"\n",
"mctx",
"=",
"mctx",
".",
"WithLogTag",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"mctx",
".",
"Trace",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
",",
"rpcName",
",",
"encrypted",
",",
"arg",
")",
",",
"func",
"(",
")",
"error",
"{",
"return",
"err",
"}",
")",
"(",
")",
"\n\n",
"found",
",",
"err",
":=",
"c",
".",
"get",
"(",
"mctx",
",",
"version",
",",
"rpcName",
",",
"encrypted",
",",
"arg",
",",
"resPtr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// If we know we're not connected, use the cache value right away.",
"// TODO: API calls shouldn't necessarily depend on the",
"// connectivity as measured by gregor.",
"if",
"mctx",
".",
"G",
"(",
")",
".",
"ConnectivityMonitor",
".",
"IsConnected",
"(",
"mctx",
".",
"Ctx",
"(",
")",
")",
"==",
"libkb",
".",
"ConnectivityMonitorNo",
"{",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"libkb",
".",
"OfflineError",
"{",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"// resPtr was filled in by get()",
"\n",
"}",
"\n\n",
"type",
"handlerRes",
"struct",
"{",
"res",
"interface",
"{",
"}",
"\n",
"err",
"error",
"\n",
"}",
"\n",
"resCh",
":=",
"make",
"(",
"chan",
"handlerRes",
",",
"1",
")",
"\n\n",
"// New goroutine needs a new metacontext, in case the original",
"// gets canceled after the timeout below. Preserve the log tags",
"// though.",
"newMctx",
":=",
"mctx",
".",
"BackgroundWithLogTags",
"(",
")",
"\n\n",
"// Launch a background goroutine to try to invoke the handler.",
"// Even if we hit a timeout below and return the cached value,",
"// this goroutine will keep going in an attempt to populate the",
"// cache on a slow network.",
"go",
"func",
"(",
")",
"{",
"res",
",",
"err",
":=",
"handler",
"(",
"newMctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"resCh",
"<-",
"handlerRes",
"{",
"res",
",",
"err",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"tmp",
":=",
"c",
".",
"put",
"(",
"newMctx",
",",
"version",
",",
"rpcName",
",",
"encrypted",
",",
"arg",
",",
"res",
")",
"\n",
"if",
"tmp",
"!=",
"nil",
"{",
"newMctx",
".",
"Warning",
"(",
"\"",
"\"",
",",
"tmp",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"resCh",
"<-",
"handlerRes",
"{",
"res",
",",
"nil",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"timerCh",
"<-",
"chan",
"time",
".",
"Time",
"\n",
"if",
"found",
"{",
"// Use a quick timeout if there's an available cached value.",
"timerCh",
"=",
"mctx",
".",
"G",
"(",
")",
".",
"Clock",
"(",
")",
".",
"After",
"(",
"bestEffortHandlerTimeout",
")",
"\n",
"}",
"else",
"{",
"// Wait indefinitely on the handler if there's nothing in the cache.",
"timerCh",
"=",
"make",
"(",
"chan",
"time",
".",
"Time",
")",
"\n",
"}",
"\n",
"select",
"{",
"case",
"hr",
":=",
"<-",
"resCh",
":",
"// Explicitly return hr.res rather than nil in the err != nil",
"// case, because some RPCs might depend on getting a result",
"// along with an error.",
"return",
"hr",
".",
"res",
",",
"hr",
".",
"err",
"\n",
"case",
"<-",
"timerCh",
":",
"mctx",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"res",
",",
"nil",
"\n",
"case",
"<-",
"mctx",
".",
"Ctx",
"(",
")",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"mctx",
".",
"Ctx",
"(",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Serve an RPC out of the offline cache. The machinery only kicks
// into gear if the `oa` OfflineAvailability mode is set to
// BEST_EFFORT. If not, then just use the function `handler` which
// does the main work of handling the RPC. Note that `handler` must
// not modify anything in the caller's stack frame; it might be run in
// a background goroutine after this function returns, to populate the
// cache. `handler` also returns the return value for the RPC as an
// interface, so it can be inserted into the offline cache in the
// success case. We also pass this function a `version`, which will
// tell the cache-access machinery to fail if the wrong version of the
// data is cached. Next, we pass the `rpcName`, the argument, and the
// pointer to which the result is stored if we hit the cache.
//
// If this function doesn't return an error, and the returned `res` is
// nil, then `resPtr` will have been filled in already by the cache.
// Otherwise, `res` should be used by the caller as the response. | [
"Serve",
"an",
"RPC",
"out",
"of",
"the",
"offline",
"cache",
".",
"The",
"machinery",
"only",
"kicks",
"into",
"gear",
"if",
"the",
"oa",
"OfflineAvailability",
"mode",
"is",
"set",
"to",
"BEST_EFFORT",
".",
"If",
"not",
"then",
"just",
"use",
"the",
"function",
"handler",
"which",
"does",
"the",
"main",
"work",
"of",
"handling",
"the",
"RPC",
".",
"Note",
"that",
"handler",
"must",
"not",
"modify",
"anything",
"in",
"the",
"caller",
"s",
"stack",
"frame",
";",
"it",
"might",
"be",
"run",
"in",
"a",
"background",
"goroutine",
"after",
"this",
"function",
"returns",
"to",
"populate",
"the",
"cache",
".",
"handler",
"also",
"returns",
"the",
"return",
"value",
"for",
"the",
"RPC",
"as",
"an",
"interface",
"so",
"it",
"can",
"be",
"inserted",
"into",
"the",
"offline",
"cache",
"in",
"the",
"success",
"case",
".",
"We",
"also",
"pass",
"this",
"function",
"a",
"version",
"which",
"will",
"tell",
"the",
"cache",
"-",
"access",
"machinery",
"to",
"fail",
"if",
"the",
"wrong",
"version",
"of",
"the",
"data",
"is",
"cached",
".",
"Next",
"we",
"pass",
"the",
"rpcName",
"the",
"argument",
"and",
"the",
"pointer",
"to",
"which",
"the",
"result",
"is",
"stored",
"if",
"we",
"hit",
"the",
"cache",
".",
"If",
"this",
"function",
"doesn",
"t",
"return",
"an",
"error",
"and",
"the",
"returned",
"res",
"is",
"nil",
"then",
"resPtr",
"will",
"have",
"been",
"filled",
"in",
"already",
"by",
"the",
"cache",
".",
"Otherwise",
"res",
"should",
"be",
"used",
"by",
"the",
"caller",
"as",
"the",
"response",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/offline/rpc_cache.go#L145-L217 |
159,031 | keybase/client | go/client/cmd_simplefs_list.go | NewCmdSimpleFSList | func NewCmdSimpleFSList(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "ls",
ArgumentHelp: "<path>",
Usage: "list directory contents",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSList{Contextified: libkb.NewContextified(g)}, "ls", c)
cl.SetNoStandalone()
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rec, recursive",
Usage: "recurse into subdirectories",
},
/* TODO: currently this option does nothing.
cli.BoolFlag{
Name: "dirs-first",
Usage: "list directories first",
},
*/
cli.BoolFlag{
Name: "nocolor",
Usage: "remove color formatting",
},
cli.BoolFlag{
Name: "1, one",
Usage: "one entry per line",
},
cli.BoolFlag{
Name: "a, all",
Usage: "include entries starting with '.'",
},
cli.BoolFlag{
Name: "l, long",
Usage: "long listing",
},
cli.BoolFlag{
Name: "r, sort-reverse",
Usage: "reverse any sorting",
},
cli.BoolFlag{
Name: "t, sort-time",
Usage: "sort entries by modify time",
},
cli.BoolFlag{
Name: "s, sort-size",
Usage: "sort entries by size",
},
cli.BoolFlag{
Name: "w, windows",
Usage: "windows style dir",
},
cli.IntFlag{
Name: "rev",
Usage: "a revision number for the KBFS folder",
},
cli.StringFlag{
Name: "time",
Usage: "a time for the KBFS folder (eg \"2018-07-27 22:05\")",
},
cli.StringFlag{
Name: "reltime, relative-time",
Usage: "a relative time for the KBFS folder (eg \"5m\")",
},
},
}
} | go | func NewCmdSimpleFSList(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "ls",
ArgumentHelp: "<path>",
Usage: "list directory contents",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdSimpleFSList{Contextified: libkb.NewContextified(g)}, "ls", c)
cl.SetNoStandalone()
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rec, recursive",
Usage: "recurse into subdirectories",
},
/* TODO: currently this option does nothing.
cli.BoolFlag{
Name: "dirs-first",
Usage: "list directories first",
},
*/
cli.BoolFlag{
Name: "nocolor",
Usage: "remove color formatting",
},
cli.BoolFlag{
Name: "1, one",
Usage: "one entry per line",
},
cli.BoolFlag{
Name: "a, all",
Usage: "include entries starting with '.'",
},
cli.BoolFlag{
Name: "l, long",
Usage: "long listing",
},
cli.BoolFlag{
Name: "r, sort-reverse",
Usage: "reverse any sorting",
},
cli.BoolFlag{
Name: "t, sort-time",
Usage: "sort entries by modify time",
},
cli.BoolFlag{
Name: "s, sort-size",
Usage: "sort entries by size",
},
cli.BoolFlag{
Name: "w, windows",
Usage: "windows style dir",
},
cli.IntFlag{
Name: "rev",
Usage: "a revision number for the KBFS folder",
},
cli.StringFlag{
Name: "time",
Usage: "a time for the KBFS folder (eg \"2018-07-27 22:05\")",
},
cli.StringFlag{
Name: "reltime, relative-time",
Usage: "a relative time for the KBFS folder (eg \"5m\")",
},
},
}
} | [
"func",
"NewCmdSimpleFSList",
"(",
"cl",
"*",
"libcmdline",
".",
"CommandLine",
",",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"cli",
".",
"Command",
"{",
"return",
"cli",
".",
"Command",
"{",
"Name",
":",
"\"",
"\"",
",",
"ArgumentHelp",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"func",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"{",
"cl",
".",
"ChooseCommand",
"(",
"&",
"CmdSimpleFSList",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
"}",
",",
"\"",
"\"",
",",
"c",
")",
"\n",
"cl",
".",
"SetNoStandalone",
"(",
")",
"\n",
"}",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"/* TODO: currently this option does nothing.\n\t\t\tcli.BoolFlag{\n\t\t\t\tName: \"dirs-first\",\n\t\t\t\tUsage: \"list directories first\",\n\t\t\t},\n\t\t\t*/",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"BoolFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"IntFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"}",
",",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"}",
",",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"}"
] | // NewCmdSimpleFSList creates a new cli.Command. | [
"NewCmdSimpleFSList",
"creates",
"a",
"new",
"cli",
".",
"Command",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_simplefs_list.go#L45-L112 |
159,032 | keybase/client | go/kbfs/kbfscrypto/errors.go | Error | func (e PaddedBlockReadError) Error() string {
return fmt.Sprintf("Reading block data out of padded block resulted in %d bytes, expected %d",
e.ActualLen, e.ExpectedLen)
} | go | func (e PaddedBlockReadError) Error() string {
return fmt.Sprintf("Reading block data out of padded block resulted in %d bytes, expected %d",
e.ActualLen, e.ExpectedLen)
} | [
"func",
"(",
"e",
"PaddedBlockReadError",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"ActualLen",
",",
"e",
".",
"ExpectedLen",
")",
"\n",
"}"
] | // Error implements the error interface of PaddedBlockReadError. | [
"Error",
"implements",
"the",
"error",
"interface",
"of",
"PaddedBlockReadError",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfscrypto/errors.go#L82-L85 |
159,033 | keybase/client | go/kbfs/kbfsedits/read.go | ReadSelfWrite | func ReadSelfWrite(msg string) (ret SelfWriteMessage, err error) {
err = json.Unmarshal([]byte(msg), &ret)
if err != nil {
return SelfWriteMessage{}, err
}
return ret, nil
} | go | func ReadSelfWrite(msg string) (ret SelfWriteMessage, err error) {
err = json.Unmarshal([]byte(msg), &ret)
if err != nil {
return SelfWriteMessage{}, err
}
return ret, nil
} | [
"func",
"ReadSelfWrite",
"(",
"msg",
"string",
")",
"(",
"ret",
"SelfWriteMessage",
",",
"err",
"error",
")",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"msg",
")",
",",
"&",
"ret",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SelfWriteMessage",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // ReadSelfWrite converts the given message string into the
// SelfWriteMessage type, if possible. | [
"ReadSelfWrite",
"converts",
"the",
"given",
"message",
"string",
"into",
"the",
"SelfWriteMessage",
"type",
"if",
"possible",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/kbfsedits/read.go#L11-L17 |
159,034 | keybase/client | go/kbfs/libfuse/debug.go | MakeFuseDebugFn | func MakeFuseDebugFn(
log logger.Logger, superVerbose bool) func(msg interface{}) {
return func(msg interface{}) {
str := fmt.Sprintf("%s", msg)
// If superVerbose is not set, filter out Statfs and
// Access messages, since they're spammy on OS X.
//
// Ideally, bazil would let us filter this better, and
// also pass in the ctx.
if !superVerbose && statfsOrAccessRegexp.MatchString(str) {
return
}
log.Debug("%s", str)
}
} | go | func MakeFuseDebugFn(
log logger.Logger, superVerbose bool) func(msg interface{}) {
return func(msg interface{}) {
str := fmt.Sprintf("%s", msg)
// If superVerbose is not set, filter out Statfs and
// Access messages, since they're spammy on OS X.
//
// Ideally, bazil would let us filter this better, and
// also pass in the ctx.
if !superVerbose && statfsOrAccessRegexp.MatchString(str) {
return
}
log.Debug("%s", str)
}
} | [
"func",
"MakeFuseDebugFn",
"(",
"log",
"logger",
".",
"Logger",
",",
"superVerbose",
"bool",
")",
"func",
"(",
"msg",
"interface",
"{",
"}",
")",
"{",
"return",
"func",
"(",
"msg",
"interface",
"{",
"}",
")",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"// If superVerbose is not set, filter out Statfs and",
"// Access messages, since they're spammy on OS X.",
"//",
"// Ideally, bazil would let us filter this better, and",
"// also pass in the ctx.",
"if",
"!",
"superVerbose",
"&&",
"statfsOrAccessRegexp",
".",
"MatchString",
"(",
"str",
")",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"str",
")",
"\n",
"}",
"\n",
"}"
] | // MakeFuseDebugFn returns a function that logs its argument to the
// given log, suitable to assign to fuse.Debug. | [
"MakeFuseDebugFn",
"returns",
"a",
"function",
"that",
"logs",
"its",
"argument",
"to",
"the",
"given",
"log",
"suitable",
"to",
"assign",
"to",
"fuse",
".",
"Debug",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/debug.go#L21-L35 |
159,035 | keybase/client | go/kbfs/libfuse/debug.go | MakeFuseVDebugFn | func MakeFuseVDebugFn(
vlog *libkb.VDebugLog, superVerbose bool) func(msg interface{}) {
return func(msg interface{}) {
str := fmt.Sprintf("%s", msg)
// If superVerbose is not set, filter out Statfs and
// Access messages, since they're spammy on OS X.
//
// Ideally, bazil would let us filter this better, and
// also pass in the ctx.
if !superVerbose && statfsOrAccessRegexp.MatchString(str) {
return
}
vlog.Log(libkb.VLog1, "%s", str)
}
} | go | func MakeFuseVDebugFn(
vlog *libkb.VDebugLog, superVerbose bool) func(msg interface{}) {
return func(msg interface{}) {
str := fmt.Sprintf("%s", msg)
// If superVerbose is not set, filter out Statfs and
// Access messages, since they're spammy on OS X.
//
// Ideally, bazil would let us filter this better, and
// also pass in the ctx.
if !superVerbose && statfsOrAccessRegexp.MatchString(str) {
return
}
vlog.Log(libkb.VLog1, "%s", str)
}
} | [
"func",
"MakeFuseVDebugFn",
"(",
"vlog",
"*",
"libkb",
".",
"VDebugLog",
",",
"superVerbose",
"bool",
")",
"func",
"(",
"msg",
"interface",
"{",
"}",
")",
"{",
"return",
"func",
"(",
"msg",
"interface",
"{",
"}",
")",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"// If superVerbose is not set, filter out Statfs and",
"// Access messages, since they're spammy on OS X.",
"//",
"// Ideally, bazil would let us filter this better, and",
"// also pass in the ctx.",
"if",
"!",
"superVerbose",
"&&",
"statfsOrAccessRegexp",
".",
"MatchString",
"(",
"str",
")",
"{",
"return",
"\n",
"}",
"\n",
"vlog",
".",
"Log",
"(",
"libkb",
".",
"VLog1",
",",
"\"",
"\"",
",",
"str",
")",
"\n",
"}",
"\n",
"}"
] | // MakeFuseVDebugFn returns a function that logs its argument to the
// given vlog at level 1, suitable to assign to fuse.Debug. | [
"MakeFuseVDebugFn",
"returns",
"a",
"function",
"that",
"logs",
"its",
"argument",
"to",
"the",
"given",
"vlog",
"at",
"level",
"1",
"suitable",
"to",
"assign",
"to",
"fuse",
".",
"Debug",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/debug.go#L39-L53 |
159,036 | keybase/client | go/engine/merkle_audit.go | NewMerkleAudit | func NewMerkleAudit(g *libkb.GlobalContext, args *MerkleAuditArgs) *MerkleAudit {
task := NewBackgroundTask(g, &BackgroundTaskArgs{
Name: "MerkleAudit",
F: MerkleAuditRound,
Settings: MerkleAuditSettings,
testingMetaCh: args.testingMetaCh,
testingRoundResCh: args.testingRoundResCh,
})
return &MerkleAudit{
Contextified: libkb.NewContextified(g),
args: args,
task: task,
}
} | go | func NewMerkleAudit(g *libkb.GlobalContext, args *MerkleAuditArgs) *MerkleAudit {
task := NewBackgroundTask(g, &BackgroundTaskArgs{
Name: "MerkleAudit",
F: MerkleAuditRound,
Settings: MerkleAuditSettings,
testingMetaCh: args.testingMetaCh,
testingRoundResCh: args.testingRoundResCh,
})
return &MerkleAudit{
Contextified: libkb.NewContextified(g),
args: args,
task: task,
}
} | [
"func",
"NewMerkleAudit",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"args",
"*",
"MerkleAuditArgs",
")",
"*",
"MerkleAudit",
"{",
"task",
":=",
"NewBackgroundTask",
"(",
"g",
",",
"&",
"BackgroundTaskArgs",
"{",
"Name",
":",
"\"",
"\"",
",",
"F",
":",
"MerkleAuditRound",
",",
"Settings",
":",
"MerkleAuditSettings",
",",
"testingMetaCh",
":",
"args",
".",
"testingMetaCh",
",",
"testingRoundResCh",
":",
"args",
".",
"testingRoundResCh",
",",
"}",
")",
"\n",
"return",
"&",
"MerkleAudit",
"{",
"Contextified",
":",
"libkb",
".",
"NewContextified",
"(",
"g",
")",
",",
"args",
":",
"args",
",",
"task",
":",
"task",
",",
"}",
"\n",
"}"
] | // NewMerkleAudit creates a new MerkleAudit engine. | [
"NewMerkleAudit",
"creates",
"a",
"new",
"MerkleAudit",
"engine",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/merkle_audit.go#L55-L69 |
159,037 | keybase/client | go/engine/merkle_audit.go | randSeqno | func randSeqno(lo keybase1.Seqno, hi keybase1.Seqno, prev *keybase1.Seqno) (keybase1.Seqno, error) {
// Prevent an infinite loop if [0,1) and prev = 0
if hi-lo == 1 && prev != nil && *prev == lo {
return keybase1.Seqno(0), fmt.Errorf("unable to generate a non-duplicate seqno other than %d", *prev)
}
for {
rangeBig := big.NewInt(int64(hi - lo))
n, err := rand.Int(rand.Reader, rangeBig)
if err != nil {
return keybase1.Seqno(0), err
}
newSeqno := keybase1.Seqno(n.Int64()) + lo
if prev == nil || *prev != newSeqno {
return newSeqno, nil
}
}
} | go | func randSeqno(lo keybase1.Seqno, hi keybase1.Seqno, prev *keybase1.Seqno) (keybase1.Seqno, error) {
// Prevent an infinite loop if [0,1) and prev = 0
if hi-lo == 1 && prev != nil && *prev == lo {
return keybase1.Seqno(0), fmt.Errorf("unable to generate a non-duplicate seqno other than %d", *prev)
}
for {
rangeBig := big.NewInt(int64(hi - lo))
n, err := rand.Int(rand.Reader, rangeBig)
if err != nil {
return keybase1.Seqno(0), err
}
newSeqno := keybase1.Seqno(n.Int64()) + lo
if prev == nil || *prev != newSeqno {
return newSeqno, nil
}
}
} | [
"func",
"randSeqno",
"(",
"lo",
"keybase1",
".",
"Seqno",
",",
"hi",
"keybase1",
".",
"Seqno",
",",
"prev",
"*",
"keybase1",
".",
"Seqno",
")",
"(",
"keybase1",
".",
"Seqno",
",",
"error",
")",
"{",
"// Prevent an infinite loop if [0,1) and prev = 0",
"if",
"hi",
"-",
"lo",
"==",
"1",
"&&",
"prev",
"!=",
"nil",
"&&",
"*",
"prev",
"==",
"lo",
"{",
"return",
"keybase1",
".",
"Seqno",
"(",
"0",
")",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"prev",
")",
"\n",
"}",
"\n",
"for",
"{",
"rangeBig",
":=",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"hi",
"-",
"lo",
")",
")",
"\n",
"n",
",",
"err",
":=",
"rand",
".",
"Int",
"(",
"rand",
".",
"Reader",
",",
"rangeBig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"keybase1",
".",
"Seqno",
"(",
"0",
")",
",",
"err",
"\n",
"}",
"\n",
"newSeqno",
":=",
"keybase1",
".",
"Seqno",
"(",
"n",
".",
"Int64",
"(",
")",
")",
"+",
"lo",
"\n",
"if",
"prev",
"==",
"nil",
"||",
"*",
"prev",
"!=",
"newSeqno",
"{",
"return",
"newSeqno",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // randSeqno picks a random number between [low, high) that's different from prev. | [
"randSeqno",
"picks",
"a",
"random",
"number",
"between",
"[",
"low",
"high",
")",
"that",
"s",
"different",
"from",
"prev",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/engine/merkle_audit.go#L105-L121 |
159,038 | keybase/client | go/kbfs/libkbfs/ongoing_work_limiter.go | WaitToStart | func (owl *OngoingWorkLimiter) WaitToStart(ctx context.Context) error {
select {
case owl.permits <- struct{}{}:
return nil
case <-ctx.Done():
return ctx.Err()
}
} | go | func (owl *OngoingWorkLimiter) WaitToStart(ctx context.Context) error {
select {
case owl.permits <- struct{}{}:
return nil
case <-ctx.Done():
return ctx.Err()
}
} | [
"func",
"(",
"owl",
"*",
"OngoingWorkLimiter",
")",
"WaitToStart",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"select",
"{",
"case",
"owl",
".",
"permits",
"<-",
"struct",
"{",
"}",
"{",
"}",
":",
"return",
"nil",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // WaitToStart blocks until the limiter would allow one more routine to start
// working on the thing. | [
"WaitToStart",
"blocks",
"until",
"the",
"limiter",
"would",
"allow",
"one",
"more",
"routine",
"to",
"start",
"working",
"on",
"the",
"thing",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/ongoing_work_limiter.go#L22-L29 |
159,039 | keybase/client | go/libkb/loaduser.go | checkSelf | func (arg *LoadUserArg) checkSelf() {
if arg.self {
return
}
myuid := myUID(arg.m.G(), arg.uider)
if myuid.Exists() && arg.uid.Exists() && myuid.Equal(arg.uid) {
arg.self = true
}
} | go | func (arg *LoadUserArg) checkSelf() {
if arg.self {
return
}
myuid := myUID(arg.m.G(), arg.uider)
if myuid.Exists() && arg.uid.Exists() && myuid.Equal(arg.uid) {
arg.self = true
}
} | [
"func",
"(",
"arg",
"*",
"LoadUserArg",
")",
"checkSelf",
"(",
")",
"{",
"if",
"arg",
".",
"self",
"{",
"return",
"\n",
"}",
"\n\n",
"myuid",
":=",
"myUID",
"(",
"arg",
".",
"m",
".",
"G",
"(",
")",
",",
"arg",
".",
"uider",
")",
"\n",
"if",
"myuid",
".",
"Exists",
"(",
")",
"&&",
"arg",
".",
"uid",
".",
"Exists",
"(",
")",
"&&",
"myuid",
".",
"Equal",
"(",
"arg",
".",
"uid",
")",
"{",
"arg",
".",
"self",
"=",
"true",
"\n",
"}",
"\n",
"}"
] | // after resolution, check if this is a self load | [
"after",
"resolution",
"check",
"if",
"this",
"is",
"a",
"self",
"load"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/loaduser.go#L281-L290 |
159,040 | keybase/client | go/libkb/loaduser.go | LoadUserEmails | func LoadUserEmails(m MetaContext) (emails []keybase1.Email, err error) {
uid := m.G().GetMyUID()
res, err := m.G().API.Get(m, APIArg{
Endpoint: "user/lookup",
SessionType: APISessionTypeREQUIRED,
Args: HTTPArgs{
"uid": UIDArg(uid),
},
})
if err != nil {
return
}
emailPayloads, err := jsonhelpers.JSONGetChildren(res.Body.AtKey("them").AtKey("emails").AtKey("emails"))
if err != nil {
return nil, err
}
for _, emailPayload := range emailPayloads {
email, err := emailPayload.AtKey("email").GetString()
if err != nil {
return nil, err
}
isPrimary, err := emailPayload.AtKey("is_primary").GetInt()
if err != nil {
return nil, err
}
isVerified, err := emailPayload.AtKey("is_verified").GetInt()
if err != nil {
return nil, err
}
visibilityCode, err := emailPayload.AtKey("visibility").GetInt()
if err != nil {
return nil, err
}
emails = append(emails, keybase1.Email{
Email: keybase1.EmailAddress(email),
IsVerified: isVerified == 1,
IsPrimary: isPrimary == 1,
Visibility: keybase1.IdentityVisibility(visibilityCode),
})
}
return
} | go | func LoadUserEmails(m MetaContext) (emails []keybase1.Email, err error) {
uid := m.G().GetMyUID()
res, err := m.G().API.Get(m, APIArg{
Endpoint: "user/lookup",
SessionType: APISessionTypeREQUIRED,
Args: HTTPArgs{
"uid": UIDArg(uid),
},
})
if err != nil {
return
}
emailPayloads, err := jsonhelpers.JSONGetChildren(res.Body.AtKey("them").AtKey("emails").AtKey("emails"))
if err != nil {
return nil, err
}
for _, emailPayload := range emailPayloads {
email, err := emailPayload.AtKey("email").GetString()
if err != nil {
return nil, err
}
isPrimary, err := emailPayload.AtKey("is_primary").GetInt()
if err != nil {
return nil, err
}
isVerified, err := emailPayload.AtKey("is_verified").GetInt()
if err != nil {
return nil, err
}
visibilityCode, err := emailPayload.AtKey("visibility").GetInt()
if err != nil {
return nil, err
}
emails = append(emails, keybase1.Email{
Email: keybase1.EmailAddress(email),
IsVerified: isVerified == 1,
IsPrimary: isPrimary == 1,
Visibility: keybase1.IdentityVisibility(visibilityCode),
})
}
return
} | [
"func",
"LoadUserEmails",
"(",
"m",
"MetaContext",
")",
"(",
"emails",
"[",
"]",
"keybase1",
".",
"Email",
",",
"err",
"error",
")",
"{",
"uid",
":=",
"m",
".",
"G",
"(",
")",
".",
"GetMyUID",
"(",
")",
"\n",
"res",
",",
"err",
":=",
"m",
".",
"G",
"(",
")",
".",
"API",
".",
"Get",
"(",
"m",
",",
"APIArg",
"{",
"Endpoint",
":",
"\"",
"\"",
",",
"SessionType",
":",
"APISessionTypeREQUIRED",
",",
"Args",
":",
"HTTPArgs",
"{",
"\"",
"\"",
":",
"UIDArg",
"(",
"uid",
")",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"emailPayloads",
",",
"err",
":=",
"jsonhelpers",
".",
"JSONGetChildren",
"(",
"res",
".",
"Body",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"AtKey",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"emailPayload",
":=",
"range",
"emailPayloads",
"{",
"email",
",",
"err",
":=",
"emailPayload",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"GetString",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"isPrimary",
",",
"err",
":=",
"emailPayload",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"GetInt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"isVerified",
",",
"err",
":=",
"emailPayload",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"GetInt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"visibilityCode",
",",
"err",
":=",
"emailPayload",
".",
"AtKey",
"(",
"\"",
"\"",
")",
".",
"GetInt",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"emails",
"=",
"append",
"(",
"emails",
",",
"keybase1",
".",
"Email",
"{",
"Email",
":",
"keybase1",
".",
"EmailAddress",
"(",
"email",
")",
",",
"IsVerified",
":",
"isVerified",
"==",
"1",
",",
"IsPrimary",
":",
"isPrimary",
"==",
"1",
",",
"Visibility",
":",
"keybase1",
".",
"IdentityVisibility",
"(",
"visibilityCode",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // LoadUserEmails returns emails for logged in user | [
"LoadUserEmails",
"returns",
"emails",
"for",
"logged",
"in",
"user"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/loaduser.go#L500-L543 |
159,041 | keybase/client | go/client/cmd_simplefs_set_debug_level.go | ParseArgv | func (c *CmdSimpleFSSetDebugLevel) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return fmt.Errorf("wrong number of arguments")
}
level, err := strconv.Atoi(ctx.Args()[0])
if err != nil {
return fmt.Errorf("The log level must be an integer")
}
c.level = libkb.VDebugLevel(level).String()
return nil
} | go | func (c *CmdSimpleFSSetDebugLevel) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return fmt.Errorf("wrong number of arguments")
}
level, err := strconv.Atoi(ctx.Args()[0])
if err != nil {
return fmt.Errorf("The log level must be an integer")
}
c.level = libkb.VDebugLevel(level).String()
return nil
} | [
"func",
"(",
"c",
"*",
"CmdSimpleFSSetDebugLevel",
")",
"ParseArgv",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"if",
"len",
"(",
"ctx",
".",
"Args",
"(",
")",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"level",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ctx",
".",
"Args",
"(",
")",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"level",
"=",
"libkb",
".",
"VDebugLevel",
"(",
"level",
")",
".",
"String",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ParseArgv gets and validates the level string. | [
"ParseArgv",
"gets",
"and",
"validates",
"the",
"level",
"string",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/cmd_simplefs_set_debug_level.go#L48-L59 |
159,042 | keybase/client | go/client/chat_cli_rendering.go | convName | func (v conversationListView) convName(g *libkb.GlobalContext, conv chat1.ConversationLocal, myUsername string) string {
switch conv.GetMembersType() {
case chat1.ConversationMembersType_TEAM:
return v.convNameTeam(g, conv)
case chat1.ConversationMembersType_KBFS, chat1.ConversationMembersType_IMPTEAMNATIVE,
chat1.ConversationMembersType_IMPTEAMUPGRADE:
return v.convNameKBFS(g, conv, myUsername)
}
return ""
} | go | func (v conversationListView) convName(g *libkb.GlobalContext, conv chat1.ConversationLocal, myUsername string) string {
switch conv.GetMembersType() {
case chat1.ConversationMembersType_TEAM:
return v.convNameTeam(g, conv)
case chat1.ConversationMembersType_KBFS, chat1.ConversationMembersType_IMPTEAMNATIVE,
chat1.ConversationMembersType_IMPTEAMUPGRADE:
return v.convNameKBFS(g, conv, myUsername)
}
return ""
} | [
"func",
"(",
"v",
"conversationListView",
")",
"convName",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"conv",
"chat1",
".",
"ConversationLocal",
",",
"myUsername",
"string",
")",
"string",
"{",
"switch",
"conv",
".",
"GetMembersType",
"(",
")",
"{",
"case",
"chat1",
".",
"ConversationMembersType_TEAM",
":",
"return",
"v",
".",
"convNameTeam",
"(",
"g",
",",
"conv",
")",
"\n",
"case",
"chat1",
".",
"ConversationMembersType_KBFS",
",",
"chat1",
".",
"ConversationMembersType_IMPTEAMNATIVE",
",",
"chat1",
".",
"ConversationMembersType_IMPTEAMUPGRADE",
":",
"return",
"v",
".",
"convNameKBFS",
"(",
"g",
",",
"conv",
",",
"myUsername",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Make a name that looks like a tlfname but is sorted by activity and missing
// myUsername. | [
"Make",
"a",
"name",
"that",
"looks",
"like",
"a",
"tlfname",
"but",
"is",
"sorted",
"by",
"activity",
"and",
"missing",
"myUsername",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/chat_cli_rendering.go#L108-L117 |
159,043 | keybase/client | go/client/chat_cli_rendering.go | convNameLite | func (v conversationListView) convNameLite(g *libkb.GlobalContext, convErr chat1.ConversationErrorRekey, myUsername string) string {
var name string
if convErr.TlfPublic {
name = publicConvNamePrefix + strings.Join(convErr.WriterNames, ",")
} else {
name = strings.Join(v.without(g, convErr.WriterNames, myUsername), ",")
if len(convErr.WriterNames) == 1 && convErr.WriterNames[0] == myUsername {
// The user is the only writer.
name = myUsername
}
}
if len(convErr.ReaderNames) > 0 {
name += "#" + strings.Join(convErr.ReaderNames, ",")
}
return name
} | go | func (v conversationListView) convNameLite(g *libkb.GlobalContext, convErr chat1.ConversationErrorRekey, myUsername string) string {
var name string
if convErr.TlfPublic {
name = publicConvNamePrefix + strings.Join(convErr.WriterNames, ",")
} else {
name = strings.Join(v.without(g, convErr.WriterNames, myUsername), ",")
if len(convErr.WriterNames) == 1 && convErr.WriterNames[0] == myUsername {
// The user is the only writer.
name = myUsername
}
}
if len(convErr.ReaderNames) > 0 {
name += "#" + strings.Join(convErr.ReaderNames, ",")
}
return name
} | [
"func",
"(",
"v",
"conversationListView",
")",
"convNameLite",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"convErr",
"chat1",
".",
"ConversationErrorRekey",
",",
"myUsername",
"string",
")",
"string",
"{",
"var",
"name",
"string",
"\n",
"if",
"convErr",
".",
"TlfPublic",
"{",
"name",
"=",
"publicConvNamePrefix",
"+",
"strings",
".",
"Join",
"(",
"convErr",
".",
"WriterNames",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"name",
"=",
"strings",
".",
"Join",
"(",
"v",
".",
"without",
"(",
"g",
",",
"convErr",
".",
"WriterNames",
",",
"myUsername",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"convErr",
".",
"WriterNames",
")",
"==",
"1",
"&&",
"convErr",
".",
"WriterNames",
"[",
"0",
"]",
"==",
"myUsername",
"{",
"// The user is the only writer.",
"name",
"=",
"myUsername",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"convErr",
".",
"ReaderNames",
")",
">",
"0",
"{",
"name",
"+=",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"convErr",
".",
"ReaderNames",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"name",
"\n",
"}"
] | // Make a name that looks like a tlfname but is sorted by activity and missing myUsername.
// This is the less featureful version for convs that can't be unboxed. | [
"Make",
"a",
"name",
"that",
"looks",
"like",
"a",
"tlfname",
"but",
"is",
"sorted",
"by",
"activity",
"and",
"missing",
"myUsername",
".",
"This",
"is",
"the",
"less",
"featureful",
"version",
"for",
"convs",
"that",
"can",
"t",
"be",
"unboxed",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/chat_cli_rendering.go#L121-L137 |
159,044 | keybase/client | go/client/chat_cli_rendering.go | newMessageView | func newMessageView(g *libkb.GlobalContext, conversationID chat1.ConversationID, m chat1.MessageUnboxed) (mv messageView, err error) {
state, err := m.State()
if err != nil {
return mv, fmt.Errorf("unexpected empty message")
}
switch state {
case chat1.MessageUnboxedState_ERROR:
return newMessageViewError(g, conversationID, m.Error())
case chat1.MessageUnboxedState_OUTBOX:
return newMessageViewOutbox(g, conversationID, m.Outbox())
case chat1.MessageUnboxedState_VALID:
return newMessageViewValid(g, conversationID, m.Valid())
default:
return mv, fmt.Errorf("unexpected message state: %v", state)
}
} | go | func newMessageView(g *libkb.GlobalContext, conversationID chat1.ConversationID, m chat1.MessageUnboxed) (mv messageView, err error) {
state, err := m.State()
if err != nil {
return mv, fmt.Errorf("unexpected empty message")
}
switch state {
case chat1.MessageUnboxedState_ERROR:
return newMessageViewError(g, conversationID, m.Error())
case chat1.MessageUnboxedState_OUTBOX:
return newMessageViewOutbox(g, conversationID, m.Outbox())
case chat1.MessageUnboxedState_VALID:
return newMessageViewValid(g, conversationID, m.Valid())
default:
return mv, fmt.Errorf("unexpected message state: %v", state)
}
} | [
"func",
"newMessageView",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
",",
"conversationID",
"chat1",
".",
"ConversationID",
",",
"m",
"chat1",
".",
"MessageUnboxed",
")",
"(",
"mv",
"messageView",
",",
"err",
"error",
")",
"{",
"state",
",",
"err",
":=",
"m",
".",
"State",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"mv",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"state",
"{",
"case",
"chat1",
".",
"MessageUnboxedState_ERROR",
":",
"return",
"newMessageViewError",
"(",
"g",
",",
"conversationID",
",",
"m",
".",
"Error",
"(",
")",
")",
"\n",
"case",
"chat1",
".",
"MessageUnboxedState_OUTBOX",
":",
"return",
"newMessageViewOutbox",
"(",
"g",
",",
"conversationID",
",",
"m",
".",
"Outbox",
"(",
")",
")",
"\n",
"case",
"chat1",
".",
"MessageUnboxedState_VALID",
":",
"return",
"newMessageViewValid",
"(",
"g",
",",
"conversationID",
",",
"m",
".",
"Valid",
"(",
")",
")",
"\n",
"default",
":",
"return",
"mv",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"state",
")",
"\n",
"}",
"\n\n",
"}"
] | // newMessageView extracts from a message the parts for display
// It may fetch the superseding message. So that for example a TEXT message will show its EDIT text. | [
"newMessageView",
"extracts",
"from",
"a",
"message",
"the",
"parts",
"for",
"display",
"It",
"may",
"fetch",
"the",
"superseding",
"message",
".",
"So",
"that",
"for",
"example",
"a",
"TEXT",
"message",
"will",
"show",
"its",
"EDIT",
"text",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/chat_cli_rendering.go#L722-L738 |
159,045 | keybase/client | go/kbfs/tlf/name.go | SplitExtension | func SplitExtension(name string) (
assertions, extensionSuffix string, err error) {
names := strings.SplitN(name, HandleExtensionSep, 2)
if len(names) > 2 {
return "", "", BadNameError{name}
}
if len(names) > 1 {
extensionSuffix = names[1]
}
return names[0], extensionSuffix, nil
} | go | func SplitExtension(name string) (
assertions, extensionSuffix string, err error) {
names := strings.SplitN(name, HandleExtensionSep, 2)
if len(names) > 2 {
return "", "", BadNameError{name}
}
if len(names) > 1 {
extensionSuffix = names[1]
}
return names[0], extensionSuffix, nil
} | [
"func",
"SplitExtension",
"(",
"name",
"string",
")",
"(",
"assertions",
",",
"extensionSuffix",
"string",
",",
"err",
"error",
")",
"{",
"names",
":=",
"strings",
".",
"SplitN",
"(",
"name",
",",
"HandleExtensionSep",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"names",
")",
">",
"2",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"BadNameError",
"{",
"name",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"names",
")",
">",
"1",
"{",
"extensionSuffix",
"=",
"names",
"[",
"1",
"]",
"\n",
"}",
"\n",
"return",
"names",
"[",
"0",
"]",
",",
"extensionSuffix",
",",
"nil",
"\n",
"}"
] | // SplitExtension separates any extension suffix from the assertions. | [
"SplitExtension",
"separates",
"any",
"extension",
"suffix",
"from",
"the",
"assertions",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L23-L33 |
159,046 | keybase/client | go/kbfs/tlf/name.go | SplitName | func SplitName(name string) (writerNames, readerNames []string,
extensionSuffix string, err error) {
assertions, extensionSuffix, err := SplitExtension(name)
if err != nil {
return nil, nil, "", err
}
splitNames := strings.SplitN(assertions, ReaderSep, 3)
if len(splitNames) > 2 {
return nil, nil, "", BadNameError{name}
}
writerNames = strings.Split(splitNames[0], ",")
if len(splitNames) > 1 {
readerNames = strings.Split(splitNames[1], ",")
}
return writerNames, readerNames, extensionSuffix, nil
} | go | func SplitName(name string) (writerNames, readerNames []string,
extensionSuffix string, err error) {
assertions, extensionSuffix, err := SplitExtension(name)
if err != nil {
return nil, nil, "", err
}
splitNames := strings.SplitN(assertions, ReaderSep, 3)
if len(splitNames) > 2 {
return nil, nil, "", BadNameError{name}
}
writerNames = strings.Split(splitNames[0], ",")
if len(splitNames) > 1 {
readerNames = strings.Split(splitNames[1], ",")
}
return writerNames, readerNames, extensionSuffix, nil
} | [
"func",
"SplitName",
"(",
"name",
"string",
")",
"(",
"writerNames",
",",
"readerNames",
"[",
"]",
"string",
",",
"extensionSuffix",
"string",
",",
"err",
"error",
")",
"{",
"assertions",
",",
"extensionSuffix",
",",
"err",
":=",
"SplitExtension",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"splitNames",
":=",
"strings",
".",
"SplitN",
"(",
"assertions",
",",
"ReaderSep",
",",
"3",
")",
"\n",
"if",
"len",
"(",
"splitNames",
")",
">",
"2",
"{",
"return",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"BadNameError",
"{",
"name",
"}",
"\n",
"}",
"\n",
"writerNames",
"=",
"strings",
".",
"Split",
"(",
"splitNames",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"splitNames",
")",
">",
"1",
"{",
"readerNames",
"=",
"strings",
".",
"Split",
"(",
"splitNames",
"[",
"1",
"]",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"writerNames",
",",
"readerNames",
",",
"extensionSuffix",
",",
"nil",
"\n",
"}"
] | // SplitName splits a TLF name into components. | [
"SplitName",
"splits",
"a",
"TLF",
"name",
"into",
"components",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L36-L53 |
159,047 | keybase/client | go/kbfs/tlf/name.go | MakeCanonicalName | func MakeCanonicalName(resolvedWriters []kbname.NormalizedUsername,
unresolvedWriters []keybase1.SocialAssertion,
resolvedReaders []kbname.NormalizedUsername,
unresolvedReaders []keybase1.SocialAssertion,
extensions []HandleExtension) CanonicalName {
return makeCanonicalName(
resolvedWriters, unresolvedWriters, resolvedReaders, unresolvedReaders,
extensions, false)
} | go | func MakeCanonicalName(resolvedWriters []kbname.NormalizedUsername,
unresolvedWriters []keybase1.SocialAssertion,
resolvedReaders []kbname.NormalizedUsername,
unresolvedReaders []keybase1.SocialAssertion,
extensions []HandleExtension) CanonicalName {
return makeCanonicalName(
resolvedWriters, unresolvedWriters, resolvedReaders, unresolvedReaders,
extensions, false)
} | [
"func",
"MakeCanonicalName",
"(",
"resolvedWriters",
"[",
"]",
"kbname",
".",
"NormalizedUsername",
",",
"unresolvedWriters",
"[",
"]",
"keybase1",
".",
"SocialAssertion",
",",
"resolvedReaders",
"[",
"]",
"kbname",
".",
"NormalizedUsername",
",",
"unresolvedReaders",
"[",
"]",
"keybase1",
".",
"SocialAssertion",
",",
"extensions",
"[",
"]",
"HandleExtension",
")",
"CanonicalName",
"{",
"return",
"makeCanonicalName",
"(",
"resolvedWriters",
",",
"unresolvedWriters",
",",
"resolvedReaders",
",",
"unresolvedReaders",
",",
"extensions",
",",
"false",
")",
"\n",
"}"
] | // MakeCanonicalName makes a CanonicalName from components. | [
"MakeCanonicalName",
"makes",
"a",
"CanonicalName",
"from",
"components",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L96-L104 |
159,048 | keybase/client | go/kbfs/tlf/name.go | MakeCanonicalNameForTeam | func MakeCanonicalNameForTeam(resolvedWriters []kbname.NormalizedUsername,
unresolvedWriters []keybase1.SocialAssertion,
resolvedReaders []kbname.NormalizedUsername,
unresolvedReaders []keybase1.SocialAssertion,
extensions []HandleExtension) CanonicalName {
return makeCanonicalName(
resolvedWriters, unresolvedWriters, resolvedReaders, unresolvedReaders,
extensions, true)
} | go | func MakeCanonicalNameForTeam(resolvedWriters []kbname.NormalizedUsername,
unresolvedWriters []keybase1.SocialAssertion,
resolvedReaders []kbname.NormalizedUsername,
unresolvedReaders []keybase1.SocialAssertion,
extensions []HandleExtension) CanonicalName {
return makeCanonicalName(
resolvedWriters, unresolvedWriters, resolvedReaders, unresolvedReaders,
extensions, true)
} | [
"func",
"MakeCanonicalNameForTeam",
"(",
"resolvedWriters",
"[",
"]",
"kbname",
".",
"NormalizedUsername",
",",
"unresolvedWriters",
"[",
"]",
"keybase1",
".",
"SocialAssertion",
",",
"resolvedReaders",
"[",
"]",
"kbname",
".",
"NormalizedUsername",
",",
"unresolvedReaders",
"[",
"]",
"keybase1",
".",
"SocialAssertion",
",",
"extensions",
"[",
"]",
"HandleExtension",
")",
"CanonicalName",
"{",
"return",
"makeCanonicalName",
"(",
"resolvedWriters",
",",
"unresolvedWriters",
",",
"resolvedReaders",
",",
"unresolvedReaders",
",",
"extensions",
",",
"true",
")",
"\n",
"}"
] | // MakeCanonicalNameForTeam makes a CanonicalName from components for a team. | [
"MakeCanonicalNameForTeam",
"makes",
"a",
"CanonicalName",
"from",
"components",
"for",
"a",
"team",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L107-L115 |
159,049 | keybase/client | go/kbfs/tlf/name.go | CanonicalToPreferredName | func CanonicalToPreferredName(username kbname.NormalizedUsername,
canon CanonicalName) (PreferredName, error) {
tlfname := string(canon)
if len(username) == 0 {
return PreferredName(tlfname), nil
}
ws, rs, ext, err := SplitName(tlfname)
if err != nil {
return "", err
}
if len(ws) == 0 {
return "", fmt.Errorf("TLF name %q with no writers", tlfname)
}
uname := username.String()
ws = putUserFirst(uname, ws)
rs = putUserFirst(uname, rs)
tlfname = strings.Join(ws, ",")
if len(rs) > 0 {
tlfname += ReaderSep + strings.Join(rs, ",")
}
if len(ext) > 0 {
tlfname += HandleExtensionSep + ext
}
return PreferredName(tlfname), nil
} | go | func CanonicalToPreferredName(username kbname.NormalizedUsername,
canon CanonicalName) (PreferredName, error) {
tlfname := string(canon)
if len(username) == 0 {
return PreferredName(tlfname), nil
}
ws, rs, ext, err := SplitName(tlfname)
if err != nil {
return "", err
}
if len(ws) == 0 {
return "", fmt.Errorf("TLF name %q with no writers", tlfname)
}
uname := username.String()
ws = putUserFirst(uname, ws)
rs = putUserFirst(uname, rs)
tlfname = strings.Join(ws, ",")
if len(rs) > 0 {
tlfname += ReaderSep + strings.Join(rs, ",")
}
if len(ext) > 0 {
tlfname += HandleExtensionSep + ext
}
return PreferredName(tlfname), nil
} | [
"func",
"CanonicalToPreferredName",
"(",
"username",
"kbname",
".",
"NormalizedUsername",
",",
"canon",
"CanonicalName",
")",
"(",
"PreferredName",
",",
"error",
")",
"{",
"tlfname",
":=",
"string",
"(",
"canon",
")",
"\n",
"if",
"len",
"(",
"username",
")",
"==",
"0",
"{",
"return",
"PreferredName",
"(",
"tlfname",
")",
",",
"nil",
"\n",
"}",
"\n",
"ws",
",",
"rs",
",",
"ext",
",",
"err",
":=",
"SplitName",
"(",
"tlfname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ws",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"tlfname",
")",
"\n",
"}",
"\n",
"uname",
":=",
"username",
".",
"String",
"(",
")",
"\n",
"ws",
"=",
"putUserFirst",
"(",
"uname",
",",
"ws",
")",
"\n",
"rs",
"=",
"putUserFirst",
"(",
"uname",
",",
"rs",
")",
"\n",
"tlfname",
"=",
"strings",
".",
"Join",
"(",
"ws",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"rs",
")",
">",
"0",
"{",
"tlfname",
"+=",
"ReaderSep",
"+",
"strings",
".",
"Join",
"(",
"rs",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ext",
")",
">",
"0",
"{",
"tlfname",
"+=",
"HandleExtensionSep",
"+",
"ext",
"\n",
"}",
"\n",
"return",
"PreferredName",
"(",
"tlfname",
")",
",",
"nil",
"\n",
"}"
] | // CanonicalToPreferredName returns the preferred TLF name, given a
// canonical name and a username. The username may be empty, and
// results in the canonical name being being returned unmodified. | [
"CanonicalToPreferredName",
"returns",
"the",
"preferred",
"TLF",
"name",
"given",
"a",
"canonical",
"name",
"and",
"a",
"username",
".",
"The",
"username",
"may",
"be",
"empty",
"and",
"results",
"in",
"the",
"canonical",
"name",
"being",
"being",
"returned",
"unmodified",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L136-L160 |
159,050 | keybase/client | go/kbfs/tlf/name.go | UserIsOnlyWriter | func UserIsOnlyWriter(username kbname.NormalizedUsername, canon CanonicalName) bool {
tlfname := string(canon)
if len(username) == 0 {
return false
}
ws, _, _, err := SplitName(tlfname)
if err != nil {
return false
}
return len(ws) == 1 && ws[0] == string(username)
} | go | func UserIsOnlyWriter(username kbname.NormalizedUsername, canon CanonicalName) bool {
tlfname := string(canon)
if len(username) == 0 {
return false
}
ws, _, _, err := SplitName(tlfname)
if err != nil {
return false
}
return len(ws) == 1 && ws[0] == string(username)
} | [
"func",
"UserIsOnlyWriter",
"(",
"username",
"kbname",
".",
"NormalizedUsername",
",",
"canon",
"CanonicalName",
")",
"bool",
"{",
"tlfname",
":=",
"string",
"(",
"canon",
")",
"\n",
"if",
"len",
"(",
"username",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"ws",
",",
"_",
",",
"_",
",",
"err",
":=",
"SplitName",
"(",
"tlfname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"len",
"(",
"ws",
")",
"==",
"1",
"&&",
"ws",
"[",
"0",
"]",
"==",
"string",
"(",
"username",
")",
"\n",
"}"
] | // UserIsOnlyWriter returns true if and only if username is the only writer in
// a TLF represented by canon. In any error case, false is returned. This
// function only naively looks at the TLF name, so it should only be used on
// non-team TLFs. | [
"UserIsOnlyWriter",
"returns",
"true",
"if",
"and",
"only",
"if",
"username",
"is",
"the",
"only",
"writer",
"in",
"a",
"TLF",
"represented",
"by",
"canon",
".",
"In",
"any",
"error",
"case",
"false",
"is",
"returned",
".",
"This",
"function",
"only",
"naively",
"looks",
"at",
"the",
"TLF",
"name",
"so",
"it",
"should",
"only",
"be",
"used",
"on",
"non",
"-",
"team",
"TLFs",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/tlf/name.go#L166-L176 |
159,051 | keybase/client | go/kbfs/libkbfs/key_manager.go | NewKeyManagerStandard | func NewKeyManagerStandard(config Config) *KeyManagerStandard {
log := config.MakeLogger("")
return &KeyManagerStandard{config, log, log.CloneWithAddedDepth(1)}
} | go | func NewKeyManagerStandard(config Config) *KeyManagerStandard {
log := config.MakeLogger("")
return &KeyManagerStandard{config, log, log.CloneWithAddedDepth(1)}
} | [
"func",
"NewKeyManagerStandard",
"(",
"config",
"Config",
")",
"*",
"KeyManagerStandard",
"{",
"log",
":=",
"config",
".",
"MakeLogger",
"(",
"\"",
"\"",
")",
"\n",
"return",
"&",
"KeyManagerStandard",
"{",
"config",
",",
"log",
",",
"log",
".",
"CloneWithAddedDepth",
"(",
"1",
")",
"}",
"\n",
"}"
] | // NewKeyManagerStandard returns a new KeyManagerStandard | [
"NewKeyManagerStandard",
"returns",
"a",
"new",
"KeyManagerStandard"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L32-L35 |
159,052 | keybase/client | go/kbfs/libkbfs/key_manager.go | GetTLFCryptKeyForEncryption | func (km *KeyManagerStandard) GetTLFCryptKeyForEncryption(ctx context.Context,
kmd libkey.KeyMetadata) (tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd,
kmd.LatestKeyGeneration(), false)
} | go | func (km *KeyManagerStandard) GetTLFCryptKeyForEncryption(ctx context.Context,
kmd libkey.KeyMetadata) (tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd,
kmd.LatestKeyGeneration(), false)
} | [
"func",
"(",
"km",
"*",
"KeyManagerStandard",
")",
"GetTLFCryptKeyForEncryption",
"(",
"ctx",
"context",
".",
"Context",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
")",
"(",
"tlfCryptKey",
"kbfscrypto",
".",
"TLFCryptKey",
",",
"err",
"error",
")",
"{",
"return",
"km",
".",
"getTLFCryptKeyUsingCurrentDevice",
"(",
"ctx",
",",
"kmd",
",",
"kmd",
".",
"LatestKeyGeneration",
"(",
")",
",",
"false",
")",
"\n",
"}"
] | // GetTLFCryptKeyForEncryption implements the KeyManager interface for
// KeyManagerStandard. | [
"GetTLFCryptKeyForEncryption",
"implements",
"the",
"KeyManager",
"interface",
"for",
"KeyManagerStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L39-L43 |
159,053 | keybase/client | go/kbfs/libkbfs/key_manager.go | GetTLFCryptKeyForMDDecryption | func (km *KeyManagerStandard) GetTLFCryptKeyForMDDecryption(
ctx context.Context, kmdToDecrypt, kmdWithKeys libkey.KeyMetadata) (
tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKey(ctx, kmdWithKeys, kmdToDecrypt.LatestKeyGeneration(),
getTLFCryptKeyAnyDevice|getTLFCryptKeyDoCache)
} | go | func (km *KeyManagerStandard) GetTLFCryptKeyForMDDecryption(
ctx context.Context, kmdToDecrypt, kmdWithKeys libkey.KeyMetadata) (
tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKey(ctx, kmdWithKeys, kmdToDecrypt.LatestKeyGeneration(),
getTLFCryptKeyAnyDevice|getTLFCryptKeyDoCache)
} | [
"func",
"(",
"km",
"*",
"KeyManagerStandard",
")",
"GetTLFCryptKeyForMDDecryption",
"(",
"ctx",
"context",
".",
"Context",
",",
"kmdToDecrypt",
",",
"kmdWithKeys",
"libkey",
".",
"KeyMetadata",
")",
"(",
"tlfCryptKey",
"kbfscrypto",
".",
"TLFCryptKey",
",",
"err",
"error",
")",
"{",
"return",
"km",
".",
"getTLFCryptKey",
"(",
"ctx",
",",
"kmdWithKeys",
",",
"kmdToDecrypt",
".",
"LatestKeyGeneration",
"(",
")",
",",
"getTLFCryptKeyAnyDevice",
"|",
"getTLFCryptKeyDoCache",
")",
"\n",
"}"
] | // GetTLFCryptKeyForMDDecryption implements the KeyManager interface
// for KeyManagerStandard. | [
"GetTLFCryptKeyForMDDecryption",
"implements",
"the",
"KeyManager",
"interface",
"for",
"KeyManagerStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L47-L52 |
159,054 | keybase/client | go/kbfs/libkbfs/key_manager.go | GetTLFCryptKeyForBlockDecryption | func (km *KeyManagerStandard) GetTLFCryptKeyForBlockDecryption(
ctx context.Context, kmd libkey.KeyMetadata, blockPtr data.BlockPointer) (
tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd, blockPtr.KeyGen, true)
} | go | func (km *KeyManagerStandard) GetTLFCryptKeyForBlockDecryption(
ctx context.Context, kmd libkey.KeyMetadata, blockPtr data.BlockPointer) (
tlfCryptKey kbfscrypto.TLFCryptKey, err error) {
return km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd, blockPtr.KeyGen, true)
} | [
"func",
"(",
"km",
"*",
"KeyManagerStandard",
")",
"GetTLFCryptKeyForBlockDecryption",
"(",
"ctx",
"context",
".",
"Context",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
",",
"blockPtr",
"data",
".",
"BlockPointer",
")",
"(",
"tlfCryptKey",
"kbfscrypto",
".",
"TLFCryptKey",
",",
"err",
"error",
")",
"{",
"return",
"km",
".",
"getTLFCryptKeyUsingCurrentDevice",
"(",
"ctx",
",",
"kmd",
",",
"blockPtr",
".",
"KeyGen",
",",
"true",
")",
"\n",
"}"
] | // GetTLFCryptKeyForBlockDecryption implements the KeyManager interface for
// KeyManagerStandard. | [
"GetTLFCryptKeyForBlockDecryption",
"implements",
"the",
"KeyManager",
"interface",
"for",
"KeyManagerStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L56-L60 |
159,055 | keybase/client | go/kbfs/libkbfs/key_manager.go | GetTLFCryptKeyOfAllGenerations | func (km *KeyManagerStandard) GetTLFCryptKeyOfAllGenerations(
ctx context.Context, kmd libkey.KeyMetadata) (
keys []kbfscrypto.TLFCryptKey, err error) {
for g := kbfsmd.FirstValidKeyGen; g <= kmd.LatestKeyGeneration(); g++ {
var key kbfscrypto.TLFCryptKey
key, err = km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd, g, true)
if err != nil {
return keys, err
}
keys = append(keys, key)
}
return keys, nil
} | go | func (km *KeyManagerStandard) GetTLFCryptKeyOfAllGenerations(
ctx context.Context, kmd libkey.KeyMetadata) (
keys []kbfscrypto.TLFCryptKey, err error) {
for g := kbfsmd.FirstValidKeyGen; g <= kmd.LatestKeyGeneration(); g++ {
var key kbfscrypto.TLFCryptKey
key, err = km.getTLFCryptKeyUsingCurrentDevice(ctx, kmd, g, true)
if err != nil {
return keys, err
}
keys = append(keys, key)
}
return keys, nil
} | [
"func",
"(",
"km",
"*",
"KeyManagerStandard",
")",
"GetTLFCryptKeyOfAllGenerations",
"(",
"ctx",
"context",
".",
"Context",
",",
"kmd",
"libkey",
".",
"KeyMetadata",
")",
"(",
"keys",
"[",
"]",
"kbfscrypto",
".",
"TLFCryptKey",
",",
"err",
"error",
")",
"{",
"for",
"g",
":=",
"kbfsmd",
".",
"FirstValidKeyGen",
";",
"g",
"<=",
"kmd",
".",
"LatestKeyGeneration",
"(",
")",
";",
"g",
"++",
"{",
"var",
"key",
"kbfscrypto",
".",
"TLFCryptKey",
"\n",
"key",
",",
"err",
"=",
"km",
".",
"getTLFCryptKeyUsingCurrentDevice",
"(",
"ctx",
",",
"kmd",
",",
"g",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"keys",
",",
"err",
"\n",
"}",
"\n",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")",
"\n",
"}",
"\n",
"return",
"keys",
",",
"nil",
"\n",
"}"
] | // GetTLFCryptKeyOfAllGenerations implements the KeyManager interface for
// KeyManagerStandard. | [
"GetTLFCryptKeyOfAllGenerations",
"implements",
"the",
"KeyManager",
"interface",
"for",
"KeyManagerStandard",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L64-L76 |
159,056 | keybase/client | go/kbfs/libkbfs/key_manager.go | generateKeyMapForUsers | func (km *KeyManagerStandard) generateKeyMapForUsers(
ctx context.Context, users []keybase1.UserOrTeamID,
offline keybase1.OfflineAvailability) (
kbfsmd.UserDevicePublicKeys, error) {
keyMap := make(kbfsmd.UserDevicePublicKeys)
// TODO: parallelize
for _, w := range users {
uid := w.AsUserOrBust() // only private TLFs should call this
// HACK: clear cache
km.config.KeybaseService().FlushUserFromLocalCache(ctx, uid)
publicKeys, err := km.config.KBPKI().GetCryptPublicKeys(
ctx, uid, offline)
if err != nil {
return nil, err
}
keyMap[uid] = make(kbfsmd.DevicePublicKeys)
for _, key := range publicKeys {
keyMap[uid][key] = true
}
}
return keyMap, nil
} | go | func (km *KeyManagerStandard) generateKeyMapForUsers(
ctx context.Context, users []keybase1.UserOrTeamID,
offline keybase1.OfflineAvailability) (
kbfsmd.UserDevicePublicKeys, error) {
keyMap := make(kbfsmd.UserDevicePublicKeys)
// TODO: parallelize
for _, w := range users {
uid := w.AsUserOrBust() // only private TLFs should call this
// HACK: clear cache
km.config.KeybaseService().FlushUserFromLocalCache(ctx, uid)
publicKeys, err := km.config.KBPKI().GetCryptPublicKeys(
ctx, uid, offline)
if err != nil {
return nil, err
}
keyMap[uid] = make(kbfsmd.DevicePublicKeys)
for _, key := range publicKeys {
keyMap[uid][key] = true
}
}
return keyMap, nil
} | [
"func",
"(",
"km",
"*",
"KeyManagerStandard",
")",
"generateKeyMapForUsers",
"(",
"ctx",
"context",
".",
"Context",
",",
"users",
"[",
"]",
"keybase1",
".",
"UserOrTeamID",
",",
"offline",
"keybase1",
".",
"OfflineAvailability",
")",
"(",
"kbfsmd",
".",
"UserDevicePublicKeys",
",",
"error",
")",
"{",
"keyMap",
":=",
"make",
"(",
"kbfsmd",
".",
"UserDevicePublicKeys",
")",
"\n\n",
"// TODO: parallelize",
"for",
"_",
",",
"w",
":=",
"range",
"users",
"{",
"uid",
":=",
"w",
".",
"AsUserOrBust",
"(",
")",
"// only private TLFs should call this",
"\n",
"// HACK: clear cache",
"km",
".",
"config",
".",
"KeybaseService",
"(",
")",
".",
"FlushUserFromLocalCache",
"(",
"ctx",
",",
"uid",
")",
"\n",
"publicKeys",
",",
"err",
":=",
"km",
".",
"config",
".",
"KBPKI",
"(",
")",
".",
"GetCryptPublicKeys",
"(",
"ctx",
",",
"uid",
",",
"offline",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"keyMap",
"[",
"uid",
"]",
"=",
"make",
"(",
"kbfsmd",
".",
"DevicePublicKeys",
")",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"publicKeys",
"{",
"keyMap",
"[",
"uid",
"]",
"[",
"key",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"keyMap",
",",
"nil",
"\n",
"}"
] | // generateKeyMapForUsers returns a kbfsmd.UserDevicePublicKeys object for
// the given list of users. Note that keyless users are retained in
// the returned kbfsmd.UserDevicePublicKeys object. | [
"generateKeyMapForUsers",
"returns",
"a",
"kbfsmd",
".",
"UserDevicePublicKeys",
"object",
"for",
"the",
"given",
"list",
"of",
"users",
".",
"Note",
"that",
"keyless",
"users",
"are",
"retained",
"in",
"the",
"returned",
"kbfsmd",
".",
"UserDevicePublicKeys",
"object",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/key_manager.go#L464-L487 |
159,057 | keybase/client | go/kbfs/libdokan/file.go | ReadFile | func (f *File) ReadFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
f.folder.fs.logEnter(ctx, "ReadFile")
defer func() { f.folder.reportErr(ctx, libkbfs.ReadMode, err) }()
var nlarge int64
nlarge, err = f.folder.fs.config.KBFSOps().Read(ctx, f.node, bs, offset)
// This is safe since length of slices always fits into an int
return int(nlarge), err
} | go | func (f *File) ReadFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
f.folder.fs.logEnter(ctx, "ReadFile")
defer func() { f.folder.reportErr(ctx, libkbfs.ReadMode, err) }()
var nlarge int64
nlarge, err = f.folder.fs.config.KBFSOps().Read(ctx, f.node, bs, offset)
// This is safe since length of slices always fits into an int
return int(nlarge), err
} | [
"func",
"(",
"f",
"*",
"File",
")",
"ReadFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"fi",
"*",
"dokan",
".",
"FileInfo",
",",
"bs",
"[",
"]",
"byte",
",",
"offset",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"f",
".",
"folder",
".",
"fs",
".",
"logEnter",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"f",
".",
"folder",
".",
"reportErr",
"(",
"ctx",
",",
"libkbfs",
".",
"ReadMode",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"var",
"nlarge",
"int64",
"\n",
"nlarge",
",",
"err",
"=",
"f",
".",
"folder",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Read",
"(",
"ctx",
",",
"f",
".",
"node",
",",
"bs",
",",
"offset",
")",
"\n\n",
"// This is safe since length of slices always fits into an int",
"return",
"int",
"(",
"nlarge",
")",
",",
"err",
"\n",
"}"
] | // ReadFile for dokan reads. | [
"ReadFile",
"for",
"dokan",
"reads",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libdokan/file.go#L85-L94 |
159,058 | keybase/client | go/kbfs/libdokan/file.go | WriteFile | func (f *File) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
f.folder.fs.logEnter(ctx, "WriteFile")
defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
if offset == -1 {
ei, err := f.folder.fs.config.KBFSOps().Stat(ctx, f.node)
if err != nil {
return 0, err
}
offset = int64(ei.Size)
}
err = f.folder.fs.config.KBFSOps().Write(ctx, f.node, bs, offset)
return len(bs), err
} | go | func (f *File) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
f.folder.fs.logEnter(ctx, "WriteFile")
defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
if offset == -1 {
ei, err := f.folder.fs.config.KBFSOps().Stat(ctx, f.node)
if err != nil {
return 0, err
}
offset = int64(ei.Size)
}
err = f.folder.fs.config.KBFSOps().Write(ctx, f.node, bs, offset)
return len(bs), err
} | [
"func",
"(",
"f",
"*",
"File",
")",
"WriteFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"fi",
"*",
"dokan",
".",
"FileInfo",
",",
"bs",
"[",
"]",
"byte",
",",
"offset",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"f",
".",
"folder",
".",
"fs",
".",
"logEnter",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"f",
".",
"folder",
".",
"reportErr",
"(",
"ctx",
",",
"libkbfs",
".",
"WriteMode",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"offset",
"==",
"-",
"1",
"{",
"ei",
",",
"err",
":=",
"f",
".",
"folder",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Stat",
"(",
"ctx",
",",
"f",
".",
"node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"offset",
"=",
"int64",
"(",
"ei",
".",
"Size",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"f",
".",
"folder",
".",
"fs",
".",
"config",
".",
"KBFSOps",
"(",
")",
".",
"Write",
"(",
"ctx",
",",
"f",
".",
"node",
",",
"bs",
",",
"offset",
")",
"\n",
"return",
"len",
"(",
"bs",
")",
",",
"err",
"\n",
"}"
] | // WriteFile for dokan writes. | [
"WriteFile",
"for",
"dokan",
"writes",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libdokan/file.go#L97-L111 |
159,059 | keybase/client | go/libkb/rpc_exim.go | Export | func (ckf ComputedKeyFamily) Export() []keybase1.PublicKey {
var exportedKeys []keybase1.PublicKey
for _, key := range ckf.GetAllActiveSibkeys() {
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
for _, key := range ckf.GetAllActiveSubkeys() {
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(exportedKeys))
return exportedKeys
} | go | func (ckf ComputedKeyFamily) Export() []keybase1.PublicKey {
var exportedKeys []keybase1.PublicKey
for _, key := range ckf.GetAllActiveSibkeys() {
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
for _, key := range ckf.GetAllActiveSubkeys() {
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(exportedKeys))
return exportedKeys
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"Export",
"(",
")",
"[",
"]",
"keybase1",
".",
"PublicKey",
"{",
"var",
"exportedKeys",
"[",
"]",
"keybase1",
".",
"PublicKey",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSibkeys",
"(",
")",
"{",
"exportedKeys",
"=",
"append",
"(",
"exportedKeys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSubkeys",
"(",
")",
"{",
"exportedKeys",
"=",
"append",
"(",
"exportedKeys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"PublicKeyList",
"(",
"exportedKeys",
")",
")",
"\n",
"return",
"exportedKeys",
"\n",
"}"
] | // Export is used by IDRes. It includes PGP keys. | [
"Export",
"is",
"used",
"by",
"IDRes",
".",
"It",
"includes",
"PGP",
"keys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/rpc_exim.go#L1254-L1264 |
159,060 | keybase/client | go/libkb/rpc_exim.go | ExportDeviceKeys | func (ckf ComputedKeyFamily) ExportDeviceKeys() (exportedKeys []keybase1.PublicKey, pgpKeyCount int) {
for _, key := range ckf.GetAllActiveSibkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
pgpKeyCount++
continue
}
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
for _, key := range ckf.GetAllActiveSubkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
pgpKeyCount++
continue
}
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(exportedKeys))
return exportedKeys, pgpKeyCount
} | go | func (ckf ComputedKeyFamily) ExportDeviceKeys() (exportedKeys []keybase1.PublicKey, pgpKeyCount int) {
for _, key := range ckf.GetAllActiveSibkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
pgpKeyCount++
continue
}
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
for _, key := range ckf.GetAllActiveSubkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
pgpKeyCount++
continue
}
exportedKeys = append(exportedKeys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(exportedKeys))
return exportedKeys, pgpKeyCount
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"ExportDeviceKeys",
"(",
")",
"(",
"exportedKeys",
"[",
"]",
"keybase1",
".",
"PublicKey",
",",
"pgpKeyCount",
"int",
")",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSibkeys",
"(",
")",
"{",
"if",
"_",
",",
"isPGP",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"pgpKeyCount",
"++",
"\n",
"continue",
"\n",
"}",
"\n",
"exportedKeys",
"=",
"append",
"(",
"exportedKeys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSubkeys",
"(",
")",
"{",
"if",
"_",
",",
"isPGP",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"pgpKeyCount",
"++",
"\n",
"continue",
"\n",
"}",
"\n",
"exportedKeys",
"=",
"append",
"(",
"exportedKeys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"PublicKeyList",
"(",
"exportedKeys",
")",
")",
"\n",
"return",
"exportedKeys",
",",
"pgpKeyCount",
"\n",
"}"
] | // ExportDeviceKeys is used by ExportToUserPlusKeys. The key list
// only contains device keys. It also returns the number of PGP
// keys in the key family. | [
"ExportDeviceKeys",
"is",
"used",
"by",
"ExportToUserPlusKeys",
".",
"The",
"key",
"list",
"only",
"contains",
"device",
"keys",
".",
"It",
"also",
"returns",
"the",
"number",
"of",
"PGP",
"keys",
"in",
"the",
"key",
"family",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/rpc_exim.go#L1269-L1286 |
159,061 | keybase/client | go/libkb/rpc_exim.go | ExportPerUserKeys | func (ckf ComputedKeyFamily) ExportPerUserKeys() (ret []keybase1.PerUserKey) {
for _, k := range ckf.cki.PerUserKeys {
ret = append(ret, k)
}
sort.Sort(perUserKeyList(ret))
return ret
} | go | func (ckf ComputedKeyFamily) ExportPerUserKeys() (ret []keybase1.PerUserKey) {
for _, k := range ckf.cki.PerUserKeys {
ret = append(ret, k)
}
sort.Sort(perUserKeyList(ret))
return ret
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"ExportPerUserKeys",
"(",
")",
"(",
"ret",
"[",
"]",
"keybase1",
".",
"PerUserKey",
")",
"{",
"for",
"_",
",",
"k",
":=",
"range",
"ckf",
".",
"cki",
".",
"PerUserKeys",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"perUserKeyList",
"(",
"ret",
")",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // ExportPerUserKeys exports the per-user public KIDs. | [
"ExportPerUserKeys",
"exports",
"the",
"per",
"-",
"user",
"public",
"KIDs",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/rpc_exim.go#L1299-L1306 |
159,062 | keybase/client | go/libkb/rpc_exim.go | ExportDeletedDeviceKeys | func (ckf ComputedKeyFamily) ExportDeletedDeviceKeys() []keybase1.PublicKey {
var keys []keybase1.PublicKey
for _, key := range ckf.GetDeletedKeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
continue
}
keys = append(keys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(keys))
return keys
} | go | func (ckf ComputedKeyFamily) ExportDeletedDeviceKeys() []keybase1.PublicKey {
var keys []keybase1.PublicKey
for _, key := range ckf.GetDeletedKeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
continue
}
keys = append(keys, ckf.exportPublicKey(key))
}
sort.Sort(PublicKeyList(keys))
return keys
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"ExportDeletedDeviceKeys",
"(",
")",
"[",
"]",
"keybase1",
".",
"PublicKey",
"{",
"var",
"keys",
"[",
"]",
"keybase1",
".",
"PublicKey",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetDeletedKeys",
"(",
")",
"{",
"if",
"_",
",",
"isPGP",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"continue",
"\n",
"}",
"\n",
"keys",
"=",
"append",
"(",
"keys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"PublicKeyList",
"(",
"keys",
")",
")",
"\n",
"return",
"keys",
"\n",
"}"
] | // ExportDeletedDeviceKeys is used by ExportToUserPlusKeys. The key list
// only contains deleted device keys. | [
"ExportDeletedDeviceKeys",
"is",
"used",
"by",
"ExportToUserPlusKeys",
".",
"The",
"key",
"list",
"only",
"contains",
"deleted",
"device",
"keys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/rpc_exim.go#L1310-L1320 |
159,063 | keybase/client | go/libkb/rpc_exim.go | ExportAllPGPKeys | func (ckf ComputedKeyFamily) ExportAllPGPKeys() (keys []keybase1.PublicKey) {
for _, key := range ckf.GetAllActiveSibkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
keys = append(keys, ckf.exportPublicKey(key))
}
}
for _, key := range ckf.GetAllActiveSubkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
keys = append(keys, ckf.exportPublicKey(key))
}
}
sort.Sort(PublicKeyList(keys))
return keys
} | go | func (ckf ComputedKeyFamily) ExportAllPGPKeys() (keys []keybase1.PublicKey) {
for _, key := range ckf.GetAllActiveSibkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
keys = append(keys, ckf.exportPublicKey(key))
}
}
for _, key := range ckf.GetAllActiveSubkeys() {
if _, isPGP := key.(*PGPKeyBundle); isPGP {
keys = append(keys, ckf.exportPublicKey(key))
}
}
sort.Sort(PublicKeyList(keys))
return keys
} | [
"func",
"(",
"ckf",
"ComputedKeyFamily",
")",
"ExportAllPGPKeys",
"(",
")",
"(",
"keys",
"[",
"]",
"keybase1",
".",
"PublicKey",
")",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSibkeys",
"(",
")",
"{",
"if",
"_",
",",
"isPGP",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"ckf",
".",
"GetAllActiveSubkeys",
"(",
")",
"{",
"if",
"_",
",",
"isPGP",
":=",
"key",
".",
"(",
"*",
"PGPKeyBundle",
")",
";",
"isPGP",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"ckf",
".",
"exportPublicKey",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"PublicKeyList",
"(",
"keys",
")",
")",
"\n",
"return",
"keys",
"\n",
"}"
] | // ExportAllPGPKeys exports all pgp keys. | [
"ExportAllPGPKeys",
"exports",
"all",
"pgp",
"keys",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/libkb/rpc_exim.go#L1323-L1336 |
159,064 | keybase/client | go/kbfs/libkbfs/observer_list.go | add | func (ol *observerList) add(o Observer) {
ol.lock.Lock()
defer ol.lock.Unlock()
ol.observers = append(ol.observers, o)
} | go | func (ol *observerList) add(o Observer) {
ol.lock.Lock()
defer ol.lock.Unlock()
ol.observers = append(ol.observers, o)
} | [
"func",
"(",
"ol",
"*",
"observerList",
")",
"add",
"(",
"o",
"Observer",
")",
"{",
"ol",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ol",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"ol",
".",
"observers",
"=",
"append",
"(",
"ol",
".",
"observers",
",",
"o",
")",
"\n",
"}"
] | // It's the caller's responsibility to make sure add isn't called
// twice for the same Observer. | [
"It",
"s",
"the",
"caller",
"s",
"responsibility",
"to",
"make",
"sure",
"add",
"isn",
"t",
"called",
"twice",
"for",
"the",
"same",
"Observer",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libkbfs/observer_list.go#L26-L30 |
159,065 | keybase/client | go/client/passphrase_prompt.go | PromptPassphrase | func PromptPassphrase(g *libkb.GlobalContext) (keybase1.GetPassphraseRes, error) {
arg := libkb.DefaultPassphraseArg(libkb.NewMetaContextTODO(g))
arg.WindowTitle = "Passphrase"
arg.Prompt = fmt.Sprintf("Pick a strong passphrase (%d+ characters)", libkb.MinPassphraseLength)
arg.Type = keybase1.PassphraseType_PASS_PHRASE
return promptPassphraseWithArg(g, arg, "Please reenter your passphrase for confirmation")
} | go | func PromptPassphrase(g *libkb.GlobalContext) (keybase1.GetPassphraseRes, error) {
arg := libkb.DefaultPassphraseArg(libkb.NewMetaContextTODO(g))
arg.WindowTitle = "Passphrase"
arg.Prompt = fmt.Sprintf("Pick a strong passphrase (%d+ characters)", libkb.MinPassphraseLength)
arg.Type = keybase1.PassphraseType_PASS_PHRASE
return promptPassphraseWithArg(g, arg, "Please reenter your passphrase for confirmation")
} | [
"func",
"PromptPassphrase",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"(",
"keybase1",
".",
"GetPassphraseRes",
",",
"error",
")",
"{",
"arg",
":=",
"libkb",
".",
"DefaultPassphraseArg",
"(",
"libkb",
".",
"NewMetaContextTODO",
"(",
"g",
")",
")",
"\n",
"arg",
".",
"WindowTitle",
"=",
"\"",
"\"",
"\n",
"arg",
".",
"Prompt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"libkb",
".",
"MinPassphraseLength",
")",
"\n",
"arg",
".",
"Type",
"=",
"keybase1",
".",
"PassphraseType_PASS_PHRASE",
"\n",
"return",
"promptPassphraseWithArg",
"(",
"g",
",",
"arg",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // promptPassphrase asks the user for a passphrase.
// Used during signup. | [
"promptPassphrase",
"asks",
"the",
"user",
"for",
"a",
"passphrase",
".",
"Used",
"during",
"signup",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/passphrase_prompt.go#L17-L23 |
159,066 | keybase/client | go/client/passphrase_prompt.go | PromptNewPassphrase | func PromptNewPassphrase(g *libkb.GlobalContext) (string, error) {
arg := libkb.DefaultPassphraseArg(libkb.NewMetaContextTODO(g))
arg.WindowTitle = "Pick a new passphrase"
arg.Prompt = fmt.Sprintf("Pick a new strong passphrase (%d+ characters)", libkb.MinPassphraseLength)
arg.Type = keybase1.PassphraseType_VERIFY_PASS_PHRASE
res, err := promptPassphraseWithArg(g, arg, "Please reenter your new passphrase for confirmation")
if err != nil {
return "", err
}
return res.Passphrase, nil
} | go | func PromptNewPassphrase(g *libkb.GlobalContext) (string, error) {
arg := libkb.DefaultPassphraseArg(libkb.NewMetaContextTODO(g))
arg.WindowTitle = "Pick a new passphrase"
arg.Prompt = fmt.Sprintf("Pick a new strong passphrase (%d+ characters)", libkb.MinPassphraseLength)
arg.Type = keybase1.PassphraseType_VERIFY_PASS_PHRASE
res, err := promptPassphraseWithArg(g, arg, "Please reenter your new passphrase for confirmation")
if err != nil {
return "", err
}
return res.Passphrase, nil
} | [
"func",
"PromptNewPassphrase",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"(",
"string",
",",
"error",
")",
"{",
"arg",
":=",
"libkb",
".",
"DefaultPassphraseArg",
"(",
"libkb",
".",
"NewMetaContextTODO",
"(",
"g",
")",
")",
"\n",
"arg",
".",
"WindowTitle",
"=",
"\"",
"\"",
"\n",
"arg",
".",
"Prompt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"libkb",
".",
"MinPassphraseLength",
")",
"\n",
"arg",
".",
"Type",
"=",
"keybase1",
".",
"PassphraseType_VERIFY_PASS_PHRASE",
"\n",
"res",
",",
"err",
":=",
"promptPassphraseWithArg",
"(",
"g",
",",
"arg",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"Passphrase",
",",
"nil",
"\n",
"}"
] | // promptNewPassphrase asks the user for a new passphrase.
// Used when changing passphrases. | [
"promptNewPassphrase",
"asks",
"the",
"user",
"for",
"a",
"new",
"passphrase",
".",
"Used",
"when",
"changing",
"passphrases",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/passphrase_prompt.go#L27-L37 |
159,067 | keybase/client | go/client/passphrase_prompt.go | PromptPaperPhrase | func PromptPaperPhrase(g *libkb.GlobalContext) (string, error) {
m := libkb.NewMetaContextTODO(g)
arg := libkb.DefaultPassphraseArg(m)
arg.WindowTitle = "Enter a paper key"
arg.Prompt = "Enter a paper key"
arg.Type = keybase1.PassphraseType_PAPER_KEY
arg.Features.ShowTyping.Allow = true
arg.Features.ShowTyping.DefaultValue = true
prompter := newClientPrompter(g)
res, err := libkb.GetPassphraseUntilCheck(m, arg, prompter, &libkb.PaperChecker{})
if err != nil {
return "", err
}
return res.Passphrase, nil
} | go | func PromptPaperPhrase(g *libkb.GlobalContext) (string, error) {
m := libkb.NewMetaContextTODO(g)
arg := libkb.DefaultPassphraseArg(m)
arg.WindowTitle = "Enter a paper key"
arg.Prompt = "Enter a paper key"
arg.Type = keybase1.PassphraseType_PAPER_KEY
arg.Features.ShowTyping.Allow = true
arg.Features.ShowTyping.DefaultValue = true
prompter := newClientPrompter(g)
res, err := libkb.GetPassphraseUntilCheck(m, arg, prompter, &libkb.PaperChecker{})
if err != nil {
return "", err
}
return res.Passphrase, nil
} | [
"func",
"PromptPaperPhrase",
"(",
"g",
"*",
"libkb",
".",
"GlobalContext",
")",
"(",
"string",
",",
"error",
")",
"{",
"m",
":=",
"libkb",
".",
"NewMetaContextTODO",
"(",
"g",
")",
"\n",
"arg",
":=",
"libkb",
".",
"DefaultPassphraseArg",
"(",
"m",
")",
"\n",
"arg",
".",
"WindowTitle",
"=",
"\"",
"\"",
"\n",
"arg",
".",
"Prompt",
"=",
"\"",
"\"",
"\n",
"arg",
".",
"Type",
"=",
"keybase1",
".",
"PassphraseType_PAPER_KEY",
"\n",
"arg",
".",
"Features",
".",
"ShowTyping",
".",
"Allow",
"=",
"true",
"\n",
"arg",
".",
"Features",
".",
"ShowTyping",
".",
"DefaultValue",
"=",
"true",
"\n\n",
"prompter",
":=",
"newClientPrompter",
"(",
"g",
")",
"\n",
"res",
",",
"err",
":=",
"libkb",
".",
"GetPassphraseUntilCheck",
"(",
"m",
",",
"arg",
",",
"prompter",
",",
"&",
"libkb",
".",
"PaperChecker",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"Passphrase",
",",
"nil",
"\n",
"}"
] | // PromptPaperPhrase asks the user to enter a paper key phrase.
// Used in `rekey paper` command. | [
"PromptPaperPhrase",
"asks",
"the",
"user",
"to",
"enter",
"a",
"paper",
"key",
"phrase",
".",
"Used",
"in",
"rekey",
"paper",
"command",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/client/passphrase_prompt.go#L41-L56 |
159,068 | keybase/client | go/kbfs/libfuse/reset_caches_file.go | Write | func (f *ResetCachesFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.fs.log.CDebugf(ctx, "ResetCachesFile Write")
defer func() { err = f.fs.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
f.fs.config.ResetCaches()
resp.Size = len(req.Data)
return nil
} | go | func (f *ResetCachesFile) Write(ctx context.Context, req *fuse.WriteRequest,
resp *fuse.WriteResponse) (err error) {
f.fs.log.CDebugf(ctx, "ResetCachesFile Write")
defer func() { err = f.fs.processError(ctx, libkbfs.WriteMode, err) }()
if len(req.Data) == 0 {
return nil
}
f.fs.config.ResetCaches()
resp.Size = len(req.Data)
return nil
} | [
"func",
"(",
"f",
"*",
"ResetCachesFile",
")",
"Write",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"fuse",
".",
"WriteRequest",
",",
"resp",
"*",
"fuse",
".",
"WriteResponse",
")",
"(",
"err",
"error",
")",
"{",
"f",
".",
"fs",
".",
"log",
".",
"CDebugf",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
"=",
"f",
".",
"fs",
".",
"processError",
"(",
"ctx",
",",
"libkbfs",
".",
"WriteMode",
",",
"err",
")",
"}",
"(",
")",
"\n",
"if",
"len",
"(",
"req",
".",
"Data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"f",
".",
"fs",
".",
"config",
".",
"ResetCaches",
"(",
")",
"\n",
"resp",
".",
"Size",
"=",
"len",
"(",
"req",
".",
"Data",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Write implements the fs.HandleWriter interface for ResetCachesFile. | [
"Write",
"implements",
"the",
"fs",
".",
"HandleWriter",
"interface",
"for",
"ResetCachesFile",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/libfuse/reset_caches_file.go#L41-L51 |
159,069 | keybase/client | go/launchd/launchd.go | SetLogger | func (s *Service) SetLogger(log Log) {
if log != nil {
s.log = log
} else {
s.log = emptyLog{}
}
} | go | func (s *Service) SetLogger(log Log) {
if log != nil {
s.log = log
} else {
s.log = emptyLog{}
}
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"SetLogger",
"(",
"log",
"Log",
")",
"{",
"if",
"log",
"!=",
"nil",
"{",
"s",
".",
"log",
"=",
"log",
"\n",
"}",
"else",
"{",
"s",
".",
"log",
"=",
"emptyLog",
"{",
"}",
"\n",
"}",
"\n",
"}"
] | // SetLogger sets the logger | [
"SetLogger",
"sets",
"the",
"logger"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L42-L48 |
159,070 | keybase/client | go/launchd/launchd.go | NewPlist | func NewPlist(label string, binPath string, args []string, envVars []EnvVar, logPath string, comment string) Plist {
return Plist{
label: label,
binPath: binPath,
args: args,
envVars: envVars,
keepAlive: true,
runAtLoad: false,
logPath: logPath,
comment: comment,
}
} | go | func NewPlist(label string, binPath string, args []string, envVars []EnvVar, logPath string, comment string) Plist {
return Plist{
label: label,
binPath: binPath,
args: args,
envVars: envVars,
keepAlive: true,
runAtLoad: false,
logPath: logPath,
comment: comment,
}
} | [
"func",
"NewPlist",
"(",
"label",
"string",
",",
"binPath",
"string",
",",
"args",
"[",
"]",
"string",
",",
"envVars",
"[",
"]",
"EnvVar",
",",
"logPath",
"string",
",",
"comment",
"string",
")",
"Plist",
"{",
"return",
"Plist",
"{",
"label",
":",
"label",
",",
"binPath",
":",
"binPath",
",",
"args",
":",
"args",
",",
"envVars",
":",
"envVars",
",",
"keepAlive",
":",
"true",
",",
"runAtLoad",
":",
"false",
",",
"logPath",
":",
"logPath",
",",
"comment",
":",
"comment",
",",
"}",
"\n",
"}"
] | // NewPlist constructs a launchd service plist | [
"NewPlist",
"constructs",
"a",
"launchd",
"service",
"plist"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L77-L88 |
159,071 | keybase/client | go/launchd/launchd.go | Start | func (s Service) Start(wait time.Duration) error {
if !s.HasPlist() {
return fmt.Errorf("No service (plist) installed with label: %s", s.label)
}
plistDest := s.plistDestination()
s.log.Info("Starting %s", s.label)
// We start using load -w on plist file
output, err := exec.Command("/bin/launchctl", "load", "-w", plistDest).CombinedOutput()
s.log.Debug("Output (launchctl load): %s", string(output))
if err != nil {
return err
}
if wait > 0 {
status, waitErr := s.WaitForStatus(wait, 100*time.Millisecond)
if waitErr != nil {
return waitErr
}
if status == nil {
return fmt.Errorf("%s is not running", s.label)
}
s.log.Debug("Service status: %#v", status)
}
return nil
} | go | func (s Service) Start(wait time.Duration) error {
if !s.HasPlist() {
return fmt.Errorf("No service (plist) installed with label: %s", s.label)
}
plistDest := s.plistDestination()
s.log.Info("Starting %s", s.label)
// We start using load -w on plist file
output, err := exec.Command("/bin/launchctl", "load", "-w", plistDest).CombinedOutput()
s.log.Debug("Output (launchctl load): %s", string(output))
if err != nil {
return err
}
if wait > 0 {
status, waitErr := s.WaitForStatus(wait, 100*time.Millisecond)
if waitErr != nil {
return waitErr
}
if status == nil {
return fmt.Errorf("%s is not running", s.label)
}
s.log.Debug("Service status: %#v", status)
}
return nil
} | [
"func",
"(",
"s",
"Service",
")",
"Start",
"(",
"wait",
"time",
".",
"Duration",
")",
"error",
"{",
"if",
"!",
"s",
".",
"HasPlist",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"}",
"\n\n",
"plistDest",
":=",
"s",
".",
"plistDestination",
"(",
")",
"\n",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"// We start using load -w on plist file",
"output",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"plistDest",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"string",
"(",
"output",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"wait",
">",
"0",
"{",
"status",
",",
"waitErr",
":=",
"s",
".",
"WaitForStatus",
"(",
"wait",
",",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"if",
"waitErr",
"!=",
"nil",
"{",
"return",
"waitErr",
"\n",
"}",
"\n",
"if",
"status",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"}",
"\n",
"s",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"status",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Start will start the service. | [
"Start",
"will",
"start",
"the",
"service",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L91-L117 |
159,072 | keybase/client | go/launchd/launchd.go | HasPlist | func (s Service) HasPlist() bool {
plistDest := s.plistDestination()
if _, err := os.Stat(plistDest); os.IsNotExist(err) {
s.log.Info("HasPlist: %s does not exist", plistDest)
return false
} else if err != nil {
s.log.Info("HasPlist: %s stat error: %s", plistDest, err)
return false
}
return true
} | go | func (s Service) HasPlist() bool {
plistDest := s.plistDestination()
if _, err := os.Stat(plistDest); os.IsNotExist(err) {
s.log.Info("HasPlist: %s does not exist", plistDest)
return false
} else if err != nil {
s.log.Info("HasPlist: %s stat error: %s", plistDest, err)
return false
}
return true
} | [
"func",
"(",
"s",
"Service",
")",
"HasPlist",
"(",
")",
"bool",
"{",
"plistDest",
":=",
"s",
".",
"plistDestination",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"plistDest",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"plistDest",
")",
"\n",
"return",
"false",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"plistDest",
",",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // HasPlist returns true if service has plist installed | [
"HasPlist",
"returns",
"true",
"if",
"service",
"has",
"plist",
"installed"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L120-L131 |
159,073 | keybase/client | go/launchd/launchd.go | Restart | func (s Service) Restart(wait time.Duration) error {
return Restart(s.Label(), wait, s.log)
} | go | func (s Service) Restart(wait time.Duration) error {
return Restart(s.Label(), wait, s.log)
} | [
"func",
"(",
"s",
"Service",
")",
"Restart",
"(",
"wait",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"Restart",
"(",
"s",
".",
"Label",
"(",
")",
",",
"wait",
",",
"s",
".",
"log",
")",
"\n",
"}"
] | // Restart a service. | [
"Restart",
"a",
"service",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L172-L174 |
159,074 | keybase/client | go/launchd/launchd.go | WaitForStatus | func (s Service) WaitForStatus(wait time.Duration, delay time.Duration) (*ServiceStatus, error) {
s.log.Info("Waiting for %s to be loaded...", s.label)
return waitForStatus(wait, delay, s.LoadStatus)
} | go | func (s Service) WaitForStatus(wait time.Duration, delay time.Duration) (*ServiceStatus, error) {
s.log.Info("Waiting for %s to be loaded...", s.label)
return waitForStatus(wait, delay, s.LoadStatus)
} | [
"func",
"(",
"s",
"Service",
")",
"WaitForStatus",
"(",
"wait",
"time",
".",
"Duration",
",",
"delay",
"time",
".",
"Duration",
")",
"(",
"*",
"ServiceStatus",
",",
"error",
")",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"return",
"waitForStatus",
"(",
"wait",
",",
"delay",
",",
"s",
".",
"LoadStatus",
")",
"\n",
"}"
] | // WaitForStatus waits for service status to be available | [
"WaitForStatus",
"waits",
"for",
"service",
"status",
"to",
"be",
"available"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L182-L185 |
159,075 | keybase/client | go/launchd/launchd.go | WaitForExit | func (s Service) WaitForExit(wait time.Duration) error {
s.log.Info("Waiting for %s to exit...", s.label)
return waitForExit(wait, 200*time.Millisecond, s.LoadStatus)
} | go | func (s Service) WaitForExit(wait time.Duration) error {
s.log.Info("Waiting for %s to exit...", s.label)
return waitForExit(wait, 200*time.Millisecond, s.LoadStatus)
} | [
"func",
"(",
"s",
"Service",
")",
"WaitForExit",
"(",
"wait",
"time",
".",
"Duration",
")",
"error",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"return",
"waitForExit",
"(",
"wait",
",",
"200",
"*",
"time",
".",
"Millisecond",
",",
"s",
".",
"LoadStatus",
")",
"\n",
"}"
] | // WaitForExit waits for service to exit | [
"WaitForExit",
"waits",
"for",
"service",
"to",
"exit"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L223-L226 |
159,076 | keybase/client | go/launchd/launchd.go | Install | func (s Service) Install(p Plist, wait time.Duration) error {
return s.install(p, wait)
} | go | func (s Service) Install(p Plist, wait time.Duration) error {
return s.install(p, wait)
} | [
"func",
"(",
"s",
"Service",
")",
"Install",
"(",
"p",
"Plist",
",",
"wait",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"s",
".",
"install",
"(",
"p",
",",
"wait",
")",
"\n",
"}"
] | // Install will install the launchd service | [
"Install",
"will",
"install",
"the",
"launchd",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L258-L260 |
159,077 | keybase/client | go/launchd/launchd.go | Uninstall | func (s Service) Uninstall(wait time.Duration) error {
errs := []error{}
// It's safer to remove the plist before stopping in case stopping
// hangs the system somehow, the plist will still be removed.
plistDest := s.plistDestination()
if _, err := os.Stat(plistDest); err == nil {
s.log.Info("Removing %s", plistDest)
if err := os.Remove(plistDest); err != nil {
errs = append(errs, err)
}
}
if _, err := s.Stop(wait); err != nil {
errs = append(errs, err)
}
return libkb.CombineErrors(errs...)
} | go | func (s Service) Uninstall(wait time.Duration) error {
errs := []error{}
// It's safer to remove the plist before stopping in case stopping
// hangs the system somehow, the plist will still be removed.
plistDest := s.plistDestination()
if _, err := os.Stat(plistDest); err == nil {
s.log.Info("Removing %s", plistDest)
if err := os.Remove(plistDest); err != nil {
errs = append(errs, err)
}
}
if _, err := s.Stop(wait); err != nil {
errs = append(errs, err)
}
return libkb.CombineErrors(errs...)
} | [
"func",
"(",
"s",
"Service",
")",
"Uninstall",
"(",
"wait",
"time",
".",
"Duration",
")",
"error",
"{",
"errs",
":=",
"[",
"]",
"error",
"{",
"}",
"\n",
"// It's safer to remove the plist before stopping in case stopping",
"// hangs the system somehow, the plist will still be removed.",
"plistDest",
":=",
"s",
".",
"plistDestination",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"plistDest",
")",
";",
"err",
"==",
"nil",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"plistDest",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"plistDest",
")",
";",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"s",
".",
"Stop",
"(",
"wait",
")",
";",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"libkb",
".",
"CombineErrors",
"(",
"errs",
"...",
")",
"\n",
"}"
] | // Uninstall will uninstall the launchd service | [
"Uninstall",
"will",
"uninstall",
"the",
"launchd",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L354-L371 |
159,078 | keybase/client | go/launchd/launchd.go | ListServices | func ListServices(filters []string) (services []Service, err error) {
launchAgentDir := launchAgentDir()
if _, derr := os.Stat(launchAgentDir); os.IsNotExist(derr) {
return
}
files, err := ioutil.ReadDir(launchAgentDir)
if err != nil {
return
}
for _, f := range files {
fileName := f.Name()
suffix := ".plist"
// We care about services that contain the filter word and end in .plist
for _, filter := range filters {
if strings.HasPrefix(fileName, filter) && strings.HasSuffix(fileName, suffix) {
label := fileName[0 : len(fileName)-len(suffix)]
service := NewService(label)
services = append(services, service)
}
}
}
return
} | go | func ListServices(filters []string) (services []Service, err error) {
launchAgentDir := launchAgentDir()
if _, derr := os.Stat(launchAgentDir); os.IsNotExist(derr) {
return
}
files, err := ioutil.ReadDir(launchAgentDir)
if err != nil {
return
}
for _, f := range files {
fileName := f.Name()
suffix := ".plist"
// We care about services that contain the filter word and end in .plist
for _, filter := range filters {
if strings.HasPrefix(fileName, filter) && strings.HasSuffix(fileName, suffix) {
label := fileName[0 : len(fileName)-len(suffix)]
service := NewService(label)
services = append(services, service)
}
}
}
return
} | [
"func",
"ListServices",
"(",
"filters",
"[",
"]",
"string",
")",
"(",
"services",
"[",
"]",
"Service",
",",
"err",
"error",
")",
"{",
"launchAgentDir",
":=",
"launchAgentDir",
"(",
")",
"\n",
"if",
"_",
",",
"derr",
":=",
"os",
".",
"Stat",
"(",
"launchAgentDir",
")",
";",
"os",
".",
"IsNotExist",
"(",
"derr",
")",
"{",
"return",
"\n",
"}",
"\n",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"launchAgentDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"files",
"{",
"fileName",
":=",
"f",
".",
"Name",
"(",
")",
"\n",
"suffix",
":=",
"\"",
"\"",
"\n",
"// We care about services that contain the filter word and end in .plist",
"for",
"_",
",",
"filter",
":=",
"range",
"filters",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"fileName",
",",
"filter",
")",
"&&",
"strings",
".",
"HasSuffix",
"(",
"fileName",
",",
"suffix",
")",
"{",
"label",
":=",
"fileName",
"[",
"0",
":",
"len",
"(",
"fileName",
")",
"-",
"len",
"(",
"suffix",
")",
"]",
"\n",
"service",
":=",
"NewService",
"(",
"label",
")",
"\n",
"services",
"=",
"append",
"(",
"services",
",",
"service",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ListServices will return service with label that starts with a filter string. | [
"ListServices",
"will",
"return",
"service",
"with",
"label",
"that",
"starts",
"with",
"a",
"filter",
"string",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L374-L396 |
159,079 | keybase/client | go/launchd/launchd.go | Description | func (s ServiceStatus) Description() string {
var status string
infos := []string{}
if s.IsRunning() {
status = "Running"
infos = append(infos, fmt.Sprintf("(pid=%s)", s.pid))
} else {
status = "Not Running"
}
if s.lastExitStatus != "" {
infos = append(infos, fmt.Sprintf("exit=%s", s.lastExitStatus))
}
return status + " " + strings.Join(infos, ", ")
} | go | func (s ServiceStatus) Description() string {
var status string
infos := []string{}
if s.IsRunning() {
status = "Running"
infos = append(infos, fmt.Sprintf("(pid=%s)", s.pid))
} else {
status = "Not Running"
}
if s.lastExitStatus != "" {
infos = append(infos, fmt.Sprintf("exit=%s", s.lastExitStatus))
}
return status + " " + strings.Join(infos, ", ")
} | [
"func",
"(",
"s",
"ServiceStatus",
")",
"Description",
"(",
")",
"string",
"{",
"var",
"status",
"string",
"\n",
"infos",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"if",
"s",
".",
"IsRunning",
"(",
")",
"{",
"status",
"=",
"\"",
"\"",
"\n",
"infos",
"=",
"append",
"(",
"infos",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"pid",
")",
")",
"\n",
"}",
"else",
"{",
"status",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"s",
".",
"lastExitStatus",
"!=",
"\"",
"\"",
"{",
"infos",
"=",
"append",
"(",
"infos",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"lastExitStatus",
")",
")",
"\n",
"}",
"\n",
"return",
"status",
"+",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"infos",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Description returns service status info | [
"Description",
"returns",
"service",
"status",
"info"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L420-L433 |
159,080 | keybase/client | go/launchd/launchd.go | StatusDescription | func (s Service) StatusDescription() string {
status, err := s.LoadStatus()
if status == nil {
return fmt.Sprintf("%s: Not Running", s.label)
}
if err != nil {
return fmt.Sprintf("%s: %v", s.label, err)
}
return fmt.Sprintf("%s: %s", s.label, status.Description())
} | go | func (s Service) StatusDescription() string {
status, err := s.LoadStatus()
if status == nil {
return fmt.Sprintf("%s: Not Running", s.label)
}
if err != nil {
return fmt.Sprintf("%s: %v", s.label, err)
}
return fmt.Sprintf("%s: %s", s.label, status.Description())
} | [
"func",
"(",
"s",
"Service",
")",
"StatusDescription",
"(",
")",
"string",
"{",
"status",
",",
"err",
":=",
"s",
".",
"LoadStatus",
"(",
")",
"\n",
"if",
"status",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"label",
",",
"status",
".",
"Description",
"(",
")",
")",
"\n",
"}"
] | // StatusDescription returns the service status description | [
"StatusDescription",
"returns",
"the",
"service",
"status",
"description"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L446-L455 |
159,081 | keybase/client | go/launchd/launchd.go | LoadStatus | func (s Service) LoadStatus() (*ServiceStatus, error) {
out, err := exec.Command("/bin/launchctl", "list").Output()
if err != nil {
return nil, err
}
var pid, lastExitStatus string
var found bool
scanner := bufio.NewScanner(bytes.NewBuffer(out))
for scanner.Scan() {
line := scanner.Text()
fields := strings.Fields(line)
if len(fields) == 3 && fields[2] == s.label {
found = true
if fields[0] != "-" {
pid = fields[0]
}
if fields[1] != "-" {
lastExitStatus = fields[1]
}
}
}
if found {
// If pid is set and > 0, then clear lastExitStatus which is the
// exit status of the previous run and doesn't mean anything for
// the current state. Clearing it to avoid confusion.
pidInt, _ := strconv.ParseInt(pid, 0, 64)
if pid != "" && pidInt > 0 {
lastExitStatus = ""
}
return &ServiceStatus{label: s.label, pid: pid, lastExitStatus: lastExitStatus}, nil
}
return nil, nil
} | go | func (s Service) LoadStatus() (*ServiceStatus, error) {
out, err := exec.Command("/bin/launchctl", "list").Output()
if err != nil {
return nil, err
}
var pid, lastExitStatus string
var found bool
scanner := bufio.NewScanner(bytes.NewBuffer(out))
for scanner.Scan() {
line := scanner.Text()
fields := strings.Fields(line)
if len(fields) == 3 && fields[2] == s.label {
found = true
if fields[0] != "-" {
pid = fields[0]
}
if fields[1] != "-" {
lastExitStatus = fields[1]
}
}
}
if found {
// If pid is set and > 0, then clear lastExitStatus which is the
// exit status of the previous run and doesn't mean anything for
// the current state. Clearing it to avoid confusion.
pidInt, _ := strconv.ParseInt(pid, 0, 64)
if pid != "" && pidInt > 0 {
lastExitStatus = ""
}
return &ServiceStatus{label: s.label, pid: pid, lastExitStatus: lastExitStatus}, nil
}
return nil, nil
} | [
"func",
"(",
"s",
"Service",
")",
"LoadStatus",
"(",
")",
"(",
"*",
"ServiceStatus",
",",
"error",
")",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"pid",
",",
"lastExitStatus",
"string",
"\n",
"var",
"found",
"bool",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"bytes",
".",
"NewBuffer",
"(",
"out",
")",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"line",
":=",
"scanner",
".",
"Text",
"(",
")",
"\n",
"fields",
":=",
"strings",
".",
"Fields",
"(",
"line",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"==",
"3",
"&&",
"fields",
"[",
"2",
"]",
"==",
"s",
".",
"label",
"{",
"found",
"=",
"true",
"\n",
"if",
"fields",
"[",
"0",
"]",
"!=",
"\"",
"\"",
"{",
"pid",
"=",
"fields",
"[",
"0",
"]",
"\n",
"}",
"\n",
"if",
"fields",
"[",
"1",
"]",
"!=",
"\"",
"\"",
"{",
"lastExitStatus",
"=",
"fields",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"found",
"{",
"// If pid is set and > 0, then clear lastExitStatus which is the",
"// exit status of the previous run and doesn't mean anything for",
"// the current state. Clearing it to avoid confusion.",
"pidInt",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"pid",
",",
"0",
",",
"64",
")",
"\n",
"if",
"pid",
"!=",
"\"",
"\"",
"&&",
"pidInt",
">",
"0",
"{",
"lastExitStatus",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"&",
"ServiceStatus",
"{",
"label",
":",
"s",
".",
"label",
",",
"pid",
":",
"pid",
",",
"lastExitStatus",
":",
"lastExitStatus",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // LoadStatus returns service status | [
"LoadStatus",
"returns",
"service",
"status"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L458-L493 |
159,082 | keybase/client | go/launchd/launchd.go | CheckPlist | func (s Service) CheckPlist(plist Plist) (bool, error) {
plistDest := s.plistDestination()
return plist.Check(plistDest)
} | go | func (s Service) CheckPlist(plist Plist) (bool, error) {
plistDest := s.plistDestination()
return plist.Check(plistDest)
} | [
"func",
"(",
"s",
"Service",
")",
"CheckPlist",
"(",
"plist",
"Plist",
")",
"(",
"bool",
",",
"error",
")",
"{",
"plistDest",
":=",
"s",
".",
"plistDestination",
"(",
")",
"\n",
"return",
"plist",
".",
"Check",
"(",
"plistDest",
")",
"\n",
"}"
] | // CheckPlist returns false, if the plist destination doesn't match what we
// would install. This means the plist is old and we need to update it. | [
"CheckPlist",
"returns",
"false",
"if",
"the",
"plist",
"destination",
"doesn",
"t",
"match",
"what",
"we",
"would",
"install",
".",
"This",
"means",
"the",
"plist",
"is",
"old",
"and",
"we",
"need",
"to",
"update",
"it",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L497-L500 |
159,083 | keybase/client | go/launchd/launchd.go | Install | func Install(plist Plist, wait time.Duration, log Log) error {
service := NewService(plist.label)
service.SetLogger(log)
return service.Install(plist, wait)
} | go | func Install(plist Plist, wait time.Duration, log Log) error {
service := NewService(plist.label)
service.SetLogger(log)
return service.Install(plist, wait)
} | [
"func",
"Install",
"(",
"plist",
"Plist",
",",
"wait",
"time",
".",
"Duration",
",",
"log",
"Log",
")",
"error",
"{",
"service",
":=",
"NewService",
"(",
"plist",
".",
"label",
")",
"\n",
"service",
".",
"SetLogger",
"(",
"log",
")",
"\n",
"return",
"service",
".",
"Install",
"(",
"plist",
",",
"wait",
")",
"\n",
"}"
] | // Install will install a service | [
"Install",
"will",
"install",
"a",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L503-L507 |
159,084 | keybase/client | go/launchd/launchd.go | Uninstall | func Uninstall(label string, wait time.Duration, log Log) error {
service := NewService(label)
service.SetLogger(log)
return service.Uninstall(wait)
} | go | func Uninstall(label string, wait time.Duration, log Log) error {
service := NewService(label)
service.SetLogger(log)
return service.Uninstall(wait)
} | [
"func",
"Uninstall",
"(",
"label",
"string",
",",
"wait",
"time",
".",
"Duration",
",",
"log",
"Log",
")",
"error",
"{",
"service",
":=",
"NewService",
"(",
"label",
")",
"\n",
"service",
".",
"SetLogger",
"(",
"log",
")",
"\n",
"return",
"service",
".",
"Uninstall",
"(",
"wait",
")",
"\n",
"}"
] | // Uninstall will uninstall a service | [
"Uninstall",
"will",
"uninstall",
"a",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L510-L514 |
159,085 | keybase/client | go/launchd/launchd.go | ShowStatus | func ShowStatus(label string, log Log) error {
service := NewService(label)
service.SetLogger(log)
status, err := service.LoadStatus()
if err != nil {
return err
}
if status != nil {
log.Info("%s", status.Description())
} else {
log.Info("No service found with label: %s", label)
}
return nil
} | go | func ShowStatus(label string, log Log) error {
service := NewService(label)
service.SetLogger(log)
status, err := service.LoadStatus()
if err != nil {
return err
}
if status != nil {
log.Info("%s", status.Description())
} else {
log.Info("No service found with label: %s", label)
}
return nil
} | [
"func",
"ShowStatus",
"(",
"label",
"string",
",",
"log",
"Log",
")",
"error",
"{",
"service",
":=",
"NewService",
"(",
"label",
")",
"\n",
"service",
".",
"SetLogger",
"(",
"log",
")",
"\n",
"status",
",",
"err",
":=",
"service",
".",
"LoadStatus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"status",
"!=",
"nil",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"status",
".",
"Description",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
",",
"label",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ShowStatus shows status info for a service | [
"ShowStatus",
"shows",
"status",
"info",
"for",
"a",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L533-L546 |
159,086 | keybase/client | go/launchd/launchd.go | Restart | func Restart(label string, wait time.Duration, log Log) error {
service := NewService(label)
service.SetLogger(log)
if _, err := service.Stop(wait); err != nil {
return err
}
return service.Start(wait)
} | go | func Restart(label string, wait time.Duration, log Log) error {
service := NewService(label)
service.SetLogger(log)
if _, err := service.Stop(wait); err != nil {
return err
}
return service.Start(wait)
} | [
"func",
"Restart",
"(",
"label",
"string",
",",
"wait",
"time",
".",
"Duration",
",",
"log",
"Log",
")",
"error",
"{",
"service",
":=",
"NewService",
"(",
"label",
")",
"\n",
"service",
".",
"SetLogger",
"(",
"log",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"service",
".",
"Stop",
"(",
"wait",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"service",
".",
"Start",
"(",
"wait",
")",
"\n",
"}"
] | // Restart restarts a service | [
"Restart",
"restarts",
"a",
"service"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L549-L556 |
159,087 | keybase/client | go/launchd/launchd.go | Check | func (p Plist) Check(path string) (bool, error) {
if p.binPath == "" {
return false, fmt.Errorf("Invalid ProgramArguments")
}
// If path doesn't exist, we don't match
if _, err := os.Stat(path); os.IsNotExist(err) {
return false, nil
}
buf, err := ioutil.ReadFile(path)
if err != nil {
return false, err
}
plistXML := p.plistXML()
if string(buf) == plistXML {
return true, nil
}
return false, nil
} | go | func (p Plist) Check(path string) (bool, error) {
if p.binPath == "" {
return false, fmt.Errorf("Invalid ProgramArguments")
}
// If path doesn't exist, we don't match
if _, err := os.Stat(path); os.IsNotExist(err) {
return false, nil
}
buf, err := ioutil.ReadFile(path)
if err != nil {
return false, err
}
plistXML := p.plistXML()
if string(buf) == plistXML {
return true, nil
}
return false, nil
} | [
"func",
"(",
"p",
"Plist",
")",
"Check",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"p",
".",
"binPath",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// If path doesn't exist, we don't match",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"plistXML",
":=",
"p",
".",
"plistXML",
"(",
")",
"\n",
"if",
"string",
"(",
"buf",
")",
"==",
"plistXML",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // Check if plist matches plist at path | [
"Check",
"if",
"plist",
"matches",
"plist",
"at",
"path"
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/launchd/launchd.go#L585-L606 |
159,088 | keybase/client | go/kbfs/data/dirty_file.go | NewDirtyFile | func NewDirtyFile(file Path, dirtyBcache DirtyBlockCache) *DirtyFile {
return &DirtyFile{
Path: file,
dirtyBcache: dirtyBcache,
fileBlockStates: make(map[BlockPointer]dirtyBlockState),
}
} | go | func NewDirtyFile(file Path, dirtyBcache DirtyBlockCache) *DirtyFile {
return &DirtyFile{
Path: file,
dirtyBcache: dirtyBcache,
fileBlockStates: make(map[BlockPointer]dirtyBlockState),
}
} | [
"func",
"NewDirtyFile",
"(",
"file",
"Path",
",",
"dirtyBcache",
"DirtyBlockCache",
")",
"*",
"DirtyFile",
"{",
"return",
"&",
"DirtyFile",
"{",
"Path",
":",
"file",
",",
"dirtyBcache",
":",
"dirtyBcache",
",",
"fileBlockStates",
":",
"make",
"(",
"map",
"[",
"BlockPointer",
"]",
"dirtyBlockState",
")",
",",
"}",
"\n",
"}"
] | // NewDirtyFile constructs a new `DirtyFile` instance. | [
"NewDirtyFile",
"constructs",
"a",
"new",
"DirtyFile",
"instance",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L87-L93 |
159,089 | keybase/client | go/kbfs/data/dirty_file.go | BlockNeedsCopy | func (df *DirtyFile) BlockNeedsCopy(ptr BlockPointer) bool {
df.lock.Lock()
defer df.lock.Unlock()
return df.fileBlockStates[ptr].copy == blockNeedsCopy
} | go | func (df *DirtyFile) BlockNeedsCopy(ptr BlockPointer) bool {
df.lock.Lock()
defer df.lock.Unlock()
return df.fileBlockStates[ptr].copy == blockNeedsCopy
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"BlockNeedsCopy",
"(",
"ptr",
"BlockPointer",
")",
"bool",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
".",
"copy",
"==",
"blockNeedsCopy",
"\n",
"}"
] | // BlockNeedsCopy returns true if the block should be copied by anyone
// who next tries to modify it. | [
"BlockNeedsCopy",
"returns",
"true",
"if",
"the",
"block",
"should",
"be",
"copied",
"by",
"anyone",
"who",
"next",
"tries",
"to",
"modify",
"it",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L97-L101 |
159,090 | keybase/client | go/kbfs/data/dirty_file.go | UpdateNotYetSyncingBytes | func (df *DirtyFile) UpdateNotYetSyncingBytes(newBytes int64) {
df.lock.Lock()
defer df.lock.Unlock()
df.notYetSyncingBytes += newBytes
if df.notYetSyncingBytes < 0 {
// It would be better if we didn't have this check, but it's
// hard for folderBlockOps to account correctly when bytes in
// a syncing block are overwritten, and then the write is
// deferred (see KBFS-2157).
df.notYetSyncingBytes = 0
}
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf, newBytes, false)
} | go | func (df *DirtyFile) UpdateNotYetSyncingBytes(newBytes int64) {
df.lock.Lock()
defer df.lock.Unlock()
df.notYetSyncingBytes += newBytes
if df.notYetSyncingBytes < 0 {
// It would be better if we didn't have this check, but it's
// hard for folderBlockOps to account correctly when bytes in
// a syncing block are overwritten, and then the write is
// deferred (see KBFS-2157).
df.notYetSyncingBytes = 0
}
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf, newBytes, false)
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"UpdateNotYetSyncingBytes",
"(",
"newBytes",
"int64",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"df",
".",
"notYetSyncingBytes",
"+=",
"newBytes",
"\n",
"if",
"df",
".",
"notYetSyncingBytes",
"<",
"0",
"{",
"// It would be better if we didn't have this check, but it's",
"// hard for folderBlockOps to account correctly when bytes in",
"// a syncing block are overwritten, and then the write is",
"// deferred (see KBFS-2157).",
"df",
".",
"notYetSyncingBytes",
"=",
"0",
"\n",
"}",
"\n",
"df",
".",
"dirtyBcache",
".",
"UpdateUnsyncedBytes",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"newBytes",
",",
"false",
")",
"\n",
"}"
] | // UpdateNotYetSyncingBytes adds `newBytes` to the number of
// outstanding to-be-synced bytes. | [
"UpdateNotYetSyncingBytes",
"adds",
"newBytes",
"to",
"the",
"number",
"of",
"outstanding",
"to",
"-",
"be",
"-",
"synced",
"bytes",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L105-L117 |
159,091 | keybase/client | go/kbfs/data/dirty_file.go | IsBlockOrphaned | func (df *DirtyFile) IsBlockOrphaned(ptr BlockPointer) bool {
df.lock.Lock()
defer df.lock.Unlock()
return df.fileBlockStates[ptr].orphaned
} | go | func (df *DirtyFile) IsBlockOrphaned(ptr BlockPointer) bool {
df.lock.Lock()
defer df.lock.Unlock()
return df.fileBlockStates[ptr].orphaned
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"IsBlockOrphaned",
"(",
"ptr",
"BlockPointer",
")",
"bool",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
".",
"orphaned",
"\n",
"}"
] | // IsBlockOrphaned returns true if the block has been orphaned and can
// no longer be reached in the file. | [
"IsBlockOrphaned",
"returns",
"true",
"if",
"the",
"block",
"has",
"been",
"orphaned",
"and",
"can",
"no",
"longer",
"be",
"reached",
"in",
"the",
"file",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L160-L164 |
159,092 | keybase/client | go/kbfs/data/dirty_file.go | SetBlockSyncing | func (df *DirtyFile) SetBlockSyncing(
ctx context.Context, ptr BlockPointer) error {
df.lock.Lock()
defer df.lock.Unlock()
state := df.fileBlockStates[ptr]
if state.copy == blockNeedsCopy {
return fmt.Errorf("Trying to sync a block that isn't dirty: %v", ptr)
}
state.copy = blockNeedsCopy
state.sync = blockSyncing
block, err := df.dirtyBcache.Get(ctx, df.Path.Tlf, ptr, df.Path.Branch)
if err != nil {
// The dirty block cache must always contain the dirty block
// until the full sync is completely done. If the block is
// gone before we have even finished syncing it, that is a
// fatal bug, because no one would be able to read the dirtied
// version of the block.
panic(err)
}
fblock, ok := block.(*FileBlock)
if !ok {
panic("Dirty file syncing a non-file block")
}
state.syncSize = int64(len(fblock.Contents))
df.totalSyncBytes += state.syncSize
df.notYetSyncingBytes -= state.syncSize
df.fileBlockStates[ptr] = state
df.dirtyBcache.UpdateSyncingBytes(df.Path.Tlf, state.syncSize)
return nil
} | go | func (df *DirtyFile) SetBlockSyncing(
ctx context.Context, ptr BlockPointer) error {
df.lock.Lock()
defer df.lock.Unlock()
state := df.fileBlockStates[ptr]
if state.copy == blockNeedsCopy {
return fmt.Errorf("Trying to sync a block that isn't dirty: %v", ptr)
}
state.copy = blockNeedsCopy
state.sync = blockSyncing
block, err := df.dirtyBcache.Get(ctx, df.Path.Tlf, ptr, df.Path.Branch)
if err != nil {
// The dirty block cache must always contain the dirty block
// until the full sync is completely done. If the block is
// gone before we have even finished syncing it, that is a
// fatal bug, because no one would be able to read the dirtied
// version of the block.
panic(err)
}
fblock, ok := block.(*FileBlock)
if !ok {
panic("Dirty file syncing a non-file block")
}
state.syncSize = int64(len(fblock.Contents))
df.totalSyncBytes += state.syncSize
df.notYetSyncingBytes -= state.syncSize
df.fileBlockStates[ptr] = state
df.dirtyBcache.UpdateSyncingBytes(df.Path.Tlf, state.syncSize)
return nil
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"SetBlockSyncing",
"(",
"ctx",
"context",
".",
"Context",
",",
"ptr",
"BlockPointer",
")",
"error",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"state",
":=",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
"\n",
"if",
"state",
".",
"copy",
"==",
"blockNeedsCopy",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ptr",
")",
"\n",
"}",
"\n",
"state",
".",
"copy",
"=",
"blockNeedsCopy",
"\n",
"state",
".",
"sync",
"=",
"blockSyncing",
"\n",
"block",
",",
"err",
":=",
"df",
".",
"dirtyBcache",
".",
"Get",
"(",
"ctx",
",",
"df",
".",
"Path",
".",
"Tlf",
",",
"ptr",
",",
"df",
".",
"Path",
".",
"Branch",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// The dirty block cache must always contain the dirty block",
"// until the full sync is completely done. If the block is",
"// gone before we have even finished syncing it, that is a",
"// fatal bug, because no one would be able to read the dirtied",
"// version of the block.",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"fblock",
",",
"ok",
":=",
"block",
".",
"(",
"*",
"FileBlock",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"state",
".",
"syncSize",
"=",
"int64",
"(",
"len",
"(",
"fblock",
".",
"Contents",
")",
")",
"\n",
"df",
".",
"totalSyncBytes",
"+=",
"state",
".",
"syncSize",
"\n",
"df",
".",
"notYetSyncingBytes",
"-=",
"state",
".",
"syncSize",
"\n",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
"=",
"state",
"\n",
"df",
".",
"dirtyBcache",
".",
"UpdateSyncingBytes",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"state",
".",
"syncSize",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetBlockSyncing is called to indicate that the block pointed to by
// `ptr` is currently being synced. | [
"SetBlockSyncing",
"is",
"called",
"to",
"indicate",
"that",
"the",
"block",
"pointed",
"to",
"by",
"ptr",
"is",
"currently",
"being",
"synced",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L168-L197 |
159,093 | keybase/client | go/kbfs/data/dirty_file.go | ResetSyncingBlocksToDirty | func (df *DirtyFile) ResetSyncingBlocksToDirty() {
df.lock.Lock()
defer df.lock.Unlock()
// Reset all syncing blocks to just be dirty again
syncFinishedNeeded := false
for ptr, state := range df.fileBlockStates {
if state.orphaned {
// This block will never be sync'd again, so clear any
// bytes from the buffer.
if state.sync == blockSyncing {
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf,
-state.syncSize, true)
} else if state.sync == blockSynced {
// Some blocks did finish, so we might be able to
// increase our buffer size.
syncFinishedNeeded = true
}
state.syncSize = 0
delete(df.fileBlockStates, ptr)
continue
}
if state.sync == blockSynced {
// Re-dirty the unsynced bytes (but don't touch the total
// bytes).
df.dirtyBcache.BlockSyncFinished(df.Path.Tlf, -state.syncSize)
} else if state.sync == blockSyncing {
df.dirtyBcache.UpdateSyncingBytes(df.Path.Tlf, -state.syncSize)
}
if state.sync != blockNotSyncing {
state.copy = blockAlreadyCopied
state.sync = blockNotSyncing
state.syncSize = 0
df.fileBlockStates[ptr] = state
}
}
if syncFinishedNeeded {
df.dirtyBcache.SyncFinished(df.Path.Tlf, df.totalSyncBytes)
}
df.totalSyncBytes = 0 // all the blocks need to be re-synced.
} | go | func (df *DirtyFile) ResetSyncingBlocksToDirty() {
df.lock.Lock()
defer df.lock.Unlock()
// Reset all syncing blocks to just be dirty again
syncFinishedNeeded := false
for ptr, state := range df.fileBlockStates {
if state.orphaned {
// This block will never be sync'd again, so clear any
// bytes from the buffer.
if state.sync == blockSyncing {
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf,
-state.syncSize, true)
} else if state.sync == blockSynced {
// Some blocks did finish, so we might be able to
// increase our buffer size.
syncFinishedNeeded = true
}
state.syncSize = 0
delete(df.fileBlockStates, ptr)
continue
}
if state.sync == blockSynced {
// Re-dirty the unsynced bytes (but don't touch the total
// bytes).
df.dirtyBcache.BlockSyncFinished(df.Path.Tlf, -state.syncSize)
} else if state.sync == blockSyncing {
df.dirtyBcache.UpdateSyncingBytes(df.Path.Tlf, -state.syncSize)
}
if state.sync != blockNotSyncing {
state.copy = blockAlreadyCopied
state.sync = blockNotSyncing
state.syncSize = 0
df.fileBlockStates[ptr] = state
}
}
if syncFinishedNeeded {
df.dirtyBcache.SyncFinished(df.Path.Tlf, df.totalSyncBytes)
}
df.totalSyncBytes = 0 // all the blocks need to be re-synced.
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"ResetSyncingBlocksToDirty",
"(",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"// Reset all syncing blocks to just be dirty again",
"syncFinishedNeeded",
":=",
"false",
"\n",
"for",
"ptr",
",",
"state",
":=",
"range",
"df",
".",
"fileBlockStates",
"{",
"if",
"state",
".",
"orphaned",
"{",
"// This block will never be sync'd again, so clear any",
"// bytes from the buffer.",
"if",
"state",
".",
"sync",
"==",
"blockSyncing",
"{",
"df",
".",
"dirtyBcache",
".",
"UpdateUnsyncedBytes",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"-",
"state",
".",
"syncSize",
",",
"true",
")",
"\n",
"}",
"else",
"if",
"state",
".",
"sync",
"==",
"blockSynced",
"{",
"// Some blocks did finish, so we might be able to",
"// increase our buffer size.",
"syncFinishedNeeded",
"=",
"true",
"\n",
"}",
"\n",
"state",
".",
"syncSize",
"=",
"0",
"\n",
"delete",
"(",
"df",
".",
"fileBlockStates",
",",
"ptr",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"state",
".",
"sync",
"==",
"blockSynced",
"{",
"// Re-dirty the unsynced bytes (but don't touch the total",
"// bytes).",
"df",
".",
"dirtyBcache",
".",
"BlockSyncFinished",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"-",
"state",
".",
"syncSize",
")",
"\n",
"}",
"else",
"if",
"state",
".",
"sync",
"==",
"blockSyncing",
"{",
"df",
".",
"dirtyBcache",
".",
"UpdateSyncingBytes",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"-",
"state",
".",
"syncSize",
")",
"\n",
"}",
"\n",
"if",
"state",
".",
"sync",
"!=",
"blockNotSyncing",
"{",
"state",
".",
"copy",
"=",
"blockAlreadyCopied",
"\n",
"state",
".",
"sync",
"=",
"blockNotSyncing",
"\n",
"state",
".",
"syncSize",
"=",
"0",
"\n",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
"=",
"state",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"syncFinishedNeeded",
"{",
"df",
".",
"dirtyBcache",
".",
"SyncFinished",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"df",
".",
"totalSyncBytes",
")",
"\n",
"}",
"\n",
"df",
".",
"totalSyncBytes",
"=",
"0",
"// all the blocks need to be re-synced.",
"\n",
"}"
] | // ResetSyncingBlocksToDirty can be called when a sync failed, and all
// the syncing blocks need to transition back to being dirty. | [
"ResetSyncingBlocksToDirty",
"can",
"be",
"called",
"when",
"a",
"sync",
"failed",
"and",
"all",
"the",
"syncing",
"blocks",
"need",
"to",
"transition",
"back",
"to",
"being",
"dirty",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L201-L240 |
159,094 | keybase/client | go/kbfs/data/dirty_file.go | FinishSync | func (df *DirtyFile) FinishSync() error {
// Mark any remaining blocks as finished syncing. For now, only
// the top-level indirect block needs this because they are added
// to the blockPutState by folderBranchOps, not folderBlockOps.
df.lock.Lock()
defer df.lock.Unlock()
// Reset all syncing blocks to just be dirty again (there should
// only be one, equal to the original top block).
found := false
for ptr, state := range df.fileBlockStates {
if state.orphaned {
continue
}
if state.sync == blockSyncing {
if found {
return fmt.Errorf("Unexpected syncing block %v", ptr)
}
if ptr != df.Path.TailPointer() {
return fmt.Errorf("Unexpected syncing block %v; expected %v",
ptr, df.Path.TailPointer())
}
found = true
err := df.setBlockSyncedLocked(ptr)
if err != nil {
return err
}
}
}
df.dirtyBcache.SyncFinished(df.Path.Tlf, df.totalSyncBytes)
df.totalSyncBytes = 0
df.deferredNewBytes = 0
if df.notYetSyncingBytes > 0 {
// The sync will never happen (probably because the underlying
// file was removed).
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf,
-df.notYetSyncingBytes, false)
df.notYetSyncingBytes = 0
}
return nil
} | go | func (df *DirtyFile) FinishSync() error {
// Mark any remaining blocks as finished syncing. For now, only
// the top-level indirect block needs this because they are added
// to the blockPutState by folderBranchOps, not folderBlockOps.
df.lock.Lock()
defer df.lock.Unlock()
// Reset all syncing blocks to just be dirty again (there should
// only be one, equal to the original top block).
found := false
for ptr, state := range df.fileBlockStates {
if state.orphaned {
continue
}
if state.sync == blockSyncing {
if found {
return fmt.Errorf("Unexpected syncing block %v", ptr)
}
if ptr != df.Path.TailPointer() {
return fmt.Errorf("Unexpected syncing block %v; expected %v",
ptr, df.Path.TailPointer())
}
found = true
err := df.setBlockSyncedLocked(ptr)
if err != nil {
return err
}
}
}
df.dirtyBcache.SyncFinished(df.Path.Tlf, df.totalSyncBytes)
df.totalSyncBytes = 0
df.deferredNewBytes = 0
if df.notYetSyncingBytes > 0 {
// The sync will never happen (probably because the underlying
// file was removed).
df.dirtyBcache.UpdateUnsyncedBytes(df.Path.Tlf,
-df.notYetSyncingBytes, false)
df.notYetSyncingBytes = 0
}
return nil
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"FinishSync",
"(",
")",
"error",
"{",
"// Mark any remaining blocks as finished syncing. For now, only",
"// the top-level indirect block needs this because they are added",
"// to the blockPutState by folderBranchOps, not folderBlockOps.",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"// Reset all syncing blocks to just be dirty again (there should",
"// only be one, equal to the original top block).",
"found",
":=",
"false",
"\n",
"for",
"ptr",
",",
"state",
":=",
"range",
"df",
".",
"fileBlockStates",
"{",
"if",
"state",
".",
"orphaned",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"state",
".",
"sync",
"==",
"blockSyncing",
"{",
"if",
"found",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ptr",
")",
"\n",
"}",
"\n",
"if",
"ptr",
"!=",
"df",
".",
"Path",
".",
"TailPointer",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ptr",
",",
"df",
".",
"Path",
".",
"TailPointer",
"(",
")",
")",
"\n",
"}",
"\n",
"found",
"=",
"true",
"\n",
"err",
":=",
"df",
".",
"setBlockSyncedLocked",
"(",
"ptr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"df",
".",
"dirtyBcache",
".",
"SyncFinished",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"df",
".",
"totalSyncBytes",
")",
"\n",
"df",
".",
"totalSyncBytes",
"=",
"0",
"\n",
"df",
".",
"deferredNewBytes",
"=",
"0",
"\n",
"if",
"df",
".",
"notYetSyncingBytes",
">",
"0",
"{",
"// The sync will never happen (probably because the underlying",
"// file was removed).",
"df",
".",
"dirtyBcache",
".",
"UpdateUnsyncedBytes",
"(",
"df",
".",
"Path",
".",
"Tlf",
",",
"-",
"df",
".",
"notYetSyncingBytes",
",",
"false",
")",
"\n",
"df",
".",
"notYetSyncingBytes",
"=",
"0",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // FinishSync is called to indicate that a sync has finished
// successfully. | [
"FinishSync",
"is",
"called",
"to",
"indicate",
"that",
"a",
"sync",
"has",
"finished",
"successfully",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L270-L310 |
159,095 | keybase/client | go/kbfs/data/dirty_file.go | AddErrListener | func (df *DirtyFile) AddErrListener(listener chan<- error) {
df.lock.Lock()
defer df.lock.Unlock()
df.errListeners = append(df.errListeners, listener)
} | go | func (df *DirtyFile) AddErrListener(listener chan<- error) {
df.lock.Lock()
defer df.lock.Unlock()
df.errListeners = append(df.errListeners, listener)
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"AddErrListener",
"(",
"listener",
"chan",
"<-",
"error",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"df",
".",
"errListeners",
"=",
"append",
"(",
"df",
".",
"errListeners",
",",
"listener",
")",
"\n",
"}"
] | // AddErrListener adds a callback that will be invoked if an error
// happens during the sync. | [
"AddErrListener",
"adds",
"a",
"callback",
"that",
"will",
"be",
"invoked",
"if",
"an",
"error",
"happens",
"during",
"the",
"sync",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L314-L318 |
159,096 | keybase/client | go/kbfs/data/dirty_file.go | NotifyErrListeners | func (df *DirtyFile) NotifyErrListeners(err error) {
df.lock.Lock()
listeners := df.errListeners
df.errListeners = nil
df.lock.Unlock()
if err == nil {
return
}
for _, listener := range listeners {
listener <- err
}
} | go | func (df *DirtyFile) NotifyErrListeners(err error) {
df.lock.Lock()
listeners := df.errListeners
df.errListeners = nil
df.lock.Unlock()
if err == nil {
return
}
for _, listener := range listeners {
listener <- err
}
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"NotifyErrListeners",
"(",
"err",
"error",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"listeners",
":=",
"df",
".",
"errListeners",
"\n",
"df",
".",
"errListeners",
"=",
"nil",
"\n",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"listener",
":=",
"range",
"listeners",
"{",
"listener",
"<-",
"err",
"\n",
"}",
"\n",
"}"
] | // NotifyErrListeners notifies all registered callbacks that an error
// happened, if `err` is `nil`. It also resets the registered
// listeners. | [
"NotifyErrListeners",
"notifies",
"all",
"registered",
"callbacks",
"that",
"an",
"error",
"happened",
"if",
"err",
"is",
"nil",
".",
"It",
"also",
"resets",
"the",
"registered",
"listeners",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L323-L334 |
159,097 | keybase/client | go/kbfs/data/dirty_file.go | NumErrListeners | func (df *DirtyFile) NumErrListeners() int {
df.lock.Lock()
defer df.lock.Unlock()
return len(df.errListeners)
} | go | func (df *DirtyFile) NumErrListeners() int {
df.lock.Lock()
defer df.lock.Unlock()
return len(df.errListeners)
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"NumErrListeners",
"(",
")",
"int",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"len",
"(",
"df",
".",
"errListeners",
")",
"\n",
"}"
] | // NumErrListeners returns the number of registered error listeners. | [
"NumErrListeners",
"returns",
"the",
"number",
"of",
"registered",
"error",
"listeners",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L337-L341 |
159,098 | keybase/client | go/kbfs/data/dirty_file.go | SetBlockOrphaned | func (df *DirtyFile) SetBlockOrphaned(ptr BlockPointer, orphaned bool) {
df.lock.Lock()
defer df.lock.Unlock()
state, ok := df.fileBlockStates[ptr]
if !ok {
return
}
state.orphaned = orphaned
df.fileBlockStates[ptr] = state
} | go | func (df *DirtyFile) SetBlockOrphaned(ptr BlockPointer, orphaned bool) {
df.lock.Lock()
defer df.lock.Unlock()
state, ok := df.fileBlockStates[ptr]
if !ok {
return
}
state.orphaned = orphaned
df.fileBlockStates[ptr] = state
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"SetBlockOrphaned",
"(",
"ptr",
"BlockPointer",
",",
"orphaned",
"bool",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"state",
",",
"ok",
":=",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"state",
".",
"orphaned",
"=",
"orphaned",
"\n",
"df",
".",
"fileBlockStates",
"[",
"ptr",
"]",
"=",
"state",
"\n",
"}"
] | // SetBlockOrphaned is called to indicate that a block has been
// orphaned, and can no longer be reached within the file. | [
"SetBlockOrphaned",
"is",
"called",
"to",
"indicate",
"that",
"a",
"block",
"has",
"been",
"orphaned",
"and",
"can",
"no",
"longer",
"be",
"reached",
"within",
"the",
"file",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L345-L354 |
159,099 | keybase/client | go/kbfs/data/dirty_file.go | AddDeferredNewBytes | func (df *DirtyFile) AddDeferredNewBytes(bytes int64) {
df.lock.Lock()
defer df.lock.Unlock()
df.deferredNewBytes += bytes
} | go | func (df *DirtyFile) AddDeferredNewBytes(bytes int64) {
df.lock.Lock()
defer df.lock.Unlock()
df.deferredNewBytes += bytes
} | [
"func",
"(",
"df",
"*",
"DirtyFile",
")",
"AddDeferredNewBytes",
"(",
"bytes",
"int64",
")",
"{",
"df",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"df",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"df",
".",
"deferredNewBytes",
"+=",
"bytes",
"\n",
"}"
] | // AddDeferredNewBytes adds `bytes` to the count of all the bytes that
// have been deferred until after the current sync finishes. | [
"AddDeferredNewBytes",
"adds",
"bytes",
"to",
"the",
"count",
"of",
"all",
"the",
"bytes",
"that",
"have",
"been",
"deferred",
"until",
"after",
"the",
"current",
"sync",
"finishes",
"."
] | b352622cd8cc94798cfacbcb56ada203c18e519e | https://github.com/keybase/client/blob/b352622cd8cc94798cfacbcb56ada203c18e519e/go/kbfs/data/dirty_file.go#L358-L362 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.