lnrpc: reuse common FileExists function

This commit is contained in:
Joost Jager 2019-01-11 10:50:12 +01:00
parent 70c874be88
commit 8996a1490d
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 2 additions and 32 deletions

@ -60,16 +60,6 @@ type Server struct {
// AutopilotServer gRPC service.
var _ AutopilotServer = (*Server)(nil)
// fileExists reports whether the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// New returns a new instance of the autopilotrpc Autopilot sub-server. We also
// return the set of permissions for the macaroons that we may create within
// this method. If the macaroons we need aren't found in the filepath, then

@ -69,16 +69,6 @@ type Server struct {
// gRPC service.
var _ SignerServer = (*Server)(nil)
// fileExists reports whether the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// New returns a new instance of the signrpc Signer sub-server. We also return
// the set of permissions for the macaroons that we may create within this
// method. If the macaroons we need aren't found in the filepath, then we'll
@ -96,7 +86,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
// Now that we know the full path of the signer macaroon, we can check
// to see if we need to create it or not.
macFilePath := cfg.SignerMacPath
if cfg.MacService != nil && !fileExists(macFilePath) {
if cfg.MacService != nil && !lnrpc.FileExists(macFilePath) {
log.Infof("Making macaroons for Signer RPC Server at: %v",
macFilePath)

@ -93,16 +93,6 @@ type WalletKit struct {
// WalletKitServer gRPC service.
var _ WalletKitServer = (*WalletKit)(nil)
// fileExists reports whether the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// New creates a new instance of the WalletKit sub-RPC server.
func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
// If the path of the wallet kit macaroon wasn't specified, then we'll
@ -116,7 +106,7 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
// Now that we know the full path of the wallet kit macaroon, we can
// check to see if we need to create it or not.
macFilePath := cfg.WalletKitMacPath
if !fileExists(macFilePath) && cfg.MacService != nil {
if !lnrpc.FileExists(macFilePath) && cfg.MacService != nil {
log.Infof("Baking macaroons for WalletKit RPC Server at: %v",
macFilePath)