本文整理汇总了Golang中github.com/ipfs/go-ipfs/repo/fsrepo.LockedByOtherProcess函数的典型用法代码示例。如果您正苦于以下问题:Golang LockedByOtherProcess函数的具体用法?Golang LockedByOtherProcess怎么用?Golang LockedByOtherProcess使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LockedByOtherProcess函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: commandShouldRunOnDaemon
// commandShouldRunOnDaemon determines, from commmand details, whether a
// command ought to be executed on an IPFS daemon.
//
// It returns a client if the command should be executed on a daemon and nil if
// it should be executed on a client. It returns an error if the command must
// NOT be executed on either.
func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.Command) (cmdsHttp.Client, error) {
path := req.Path()
// root command.
if len(path) < 1 {
return nil, nil
}
if details.cannotRunOnClient && details.cannotRunOnDaemon {
return nil, fmt.Errorf("command disabled: %s", path[0])
}
if details.doesNotUseRepo && details.canRunOnClient() {
return nil, nil
}
// at this point need to know whether api is running. we defer
// to this point so that we dont check unnecessarily
// did user specify an api to use for this command?
apiAddrStr, _, err := req.Option(coreCmds.ApiOption).String()
if err != nil {
return nil, err
}
client, err := getApiClient(req.InvocContext().ConfigRoot, apiAddrStr)
if err == repo.ErrApiNotRunning {
if apiAddrStr != "" && req.Command() != daemonCmd {
// if user SPECIFIED an api, and this cmd is not daemon
// we MUST use it. so error out.
return nil, err
}
// ok for api not to be running
} else if err != nil { // some other api error
return nil, err
}
if client != nil { // daemon is running
if details.cannotRunOnDaemon {
e := "cannot use API with this command."
// check if daemon locked. legacy error text, for now.
daemonLocked, _ := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
if daemonLocked {
e = "ipfs daemon is running. please stop it to run this command"
}
return nil, cmds.ClientError(e)
}
return client, nil
}
if details.cannotRunOnClient {
return nil, cmds.ClientError("must run on the ipfs daemon")
}
return nil, nil
}
开发者ID:sroerick,项目名称:go-ipfs,代码行数:65,代码来源:main.go
示例2: commandShouldRunOnDaemon
// commandShouldRunOnDaemon determines, from commmand details, whether a
// command ought to be executed on an IPFS daemon.
//
// It returns true if the command should be executed on a daemon and false if
// it should be executed on a client. It returns an error if the command must
// NOT be executed on either.
func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.Command) (bool, error) {
path := req.Path()
// root command.
if len(path) < 1 {
return false, nil
}
if details.cannotRunOnClient && details.cannotRunOnDaemon {
return false, fmt.Errorf("command disabled: %s", path[0])
}
if details.doesNotUseRepo && details.canRunOnClient() {
return false, nil
}
// at this point need to know whether daemon is running. we defer
// to this point so that some commands dont open files unnecessarily.
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
if err != nil {
return false, err
}
if daemonLocked {
log.Info("a daemon is running...")
if details.cannotRunOnDaemon {
e := "ipfs daemon is running. please stop it to run this command"
return false, cmds.ClientError(e)
}
return true, nil
}
if details.cannotRunOnClient {
return false, cmds.ClientError("must run on the ipfs daemon")
}
return false, nil
}
开发者ID:hebelken,项目名称:go-ipfs,代码行数:46,代码来源:main.go
示例3:
`,
},
Arguments: []cmds.Argument{
cmds.FileArg("default-config", false, false, "Initialize with the given configuration.").EnableStdin(),
},
Options: []cmds.Option{
cmds.IntOption("bits", "b", fmt.Sprintf("Number of bits to use in the generated RSA private key (defaults to %d)", nBitsForKeypairDefault)),
cmds.BoolOption("empty-repo", "e", "Don't add and pin help files to the local storage."),
// TODO need to decide whether to expose the override as a file or a
// directory. That is: should we allow the user to also specify the
// name of the file?
// TODO cmds.StringOption("event-logs", "l", "Location for machine-readable event logs."),
},
PreRun: func(req cmds.Request) error {
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
if err != nil {
return err
}
log.Info("checking if daemon is running...")
if daemonLocked {
log.Debug("Ipfs daemon is running.")
e := "ipfs daemon is running. please stop it to run this command"
return cmds.ClientError(e)
}
return nil
},
Run: func(req cmds.Request, res cmds.Response) {
if req.InvocContext().Online {
开发者ID:Kubuxu,项目名称:go-ipfs,代码行数:31,代码来源:init.go
注:本文中的github.com/ipfs/go-ipfs/repo/fsrepo.LockedByOtherProcess函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论