diff --git a/config.go b/config.go index af49ce888..8a1ecf0f0 100644 --- a/config.go +++ b/config.go @@ -700,7 +700,7 @@ func LoadConfig(interceptor signal.Interceptor) (*Config, error) { // User did specify an explicit --configfile, so we check that it does // exist under that path to avoid surprises. case configFilePath != DefaultConfigFile: - if !fileExists(configFilePath) { + if !lnrpc.FileExists(configFilePath) { return nil, fmt.Errorf("specified config file does "+ "not exist in %s", configFilePath) } diff --git a/config_builder.go b/config_builder.go index cf227c0e6..0b8e5a49b 100644 --- a/config_builder.go +++ b/config_builder.go @@ -466,9 +466,9 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context, // If the user requested a stateless initialization, no macaroon // files should be created. if !walletInitParams.StatelessInit && - !fileExists(d.cfg.AdminMacPath) && - !fileExists(d.cfg.ReadMacPath) && - !fileExists(d.cfg.InvoiceMacPath) { + !lnrpc.FileExists(d.cfg.AdminMacPath) && + !lnrpc.FileExists(d.cfg.ReadMacPath) && + !lnrpc.FileExists(d.cfg.InvoiceMacPath) { // Create macaroon files for lncli to use if they don't // exist. @@ -495,13 +495,13 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context, "--new_mac_root_key with --stateless_init to " + "clean up and invalidate old macaroons." - if fileExists(d.cfg.AdminMacPath) { + if lnrpc.FileExists(d.cfg.AdminMacPath) { d.logger.Warnf(msg, "admin", d.cfg.AdminMacPath) } - if fileExists(d.cfg.ReadMacPath) { + if lnrpc.FileExists(d.cfg.ReadMacPath) { d.logger.Warnf(msg, "readonly", d.cfg.ReadMacPath) } - if fileExists(d.cfg.InvoiceMacPath) { + if lnrpc.FileExists(d.cfg.InvoiceMacPath) { d.logger.Warnf(msg, "invoice", d.cfg.InvoiceMacPath) } } diff --git a/tls_manager.go b/tls_manager.go index 495991b51..2bd174ca1 100644 --- a/tls_manager.go +++ b/tls_manager.go @@ -210,7 +210,9 @@ func (t *TLSManager) generateOrRenewCert() (*tls.Config, func(), error) { // the encrypted form. func (t *TLSManager) generateCertPair(keyRing keychain.SecretKeyRing) error { // Ensure we create TLS key and certificate if they don't exist. - if fileExists(t.cfg.TLSCertPath) || fileExists(t.cfg.TLSKeyPath) { + if lnrpc.FileExists(t.cfg.TLSCertPath) || + lnrpc.FileExists(t.cfg.TLSKeyPath) { + // Handle discrepencies related to the TLSEncryptKey setting. return t.ensureEncryption(keyRing) } @@ -597,18 +599,6 @@ func (t *TLSManager) deleteEphemeralSettings() { t.ephemeralCertPath = "" } -// fileExists reports whether the named file or directory exists. -// This function is taken from https://github.com/btcsuite/btcd -func fileExists(name string) bool { - if _, err := os.Stat(name); err != nil { - if os.IsNotExist(err) { - return false - } - } - - return true -} - // IsCertExpired checks if the current TLS certificate is expired. func (t *TLSManager) IsCertExpired(keyRing keychain.SecretKeyRing) (bool, time.Time, error) {