lnd+config: Move to FileExists function in lnrpc package
This commit is contained in:
3 files changed
+10
-20
No files matched your search
@@ -700,7 +700,7 @@ func LoadConfig(interceptor signal.Interceptor) (*Config, error) {
|
|||||||
// User did specify an explicit --configfile, so we check that it does
|
// User did specify an explicit --configfile, so we check that it does
|
||||||
// exist under that path to avoid surprises.
|
// exist under that path to avoid surprises.
|
||||||
case configFilePath != DefaultConfigFile:
|
case configFilePath != DefaultConfigFile:
|
||||||
if !fileExists(configFilePath) {
|
if !lnrpc.FileExists(configFilePath) {
|
||||||
return nil, fmt.Errorf("specified config file does "+
|
return nil, fmt.Errorf("specified config file does "+
|
||||||
"not exist in %s", configFilePath)
|
"not exist in %s", configFilePath)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -466,9 +466,9 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
|
|||||||
// If the user requested a stateless initialization, no macaroon
|
// If the user requested a stateless initialization, no macaroon
|
||||||
// files should be created.
|
// files should be created.
|
||||||
if !walletInitParams.StatelessInit &&
|
if !walletInitParams.StatelessInit &&
|
||||||
!fileExists(d.cfg.AdminMacPath) &&
|
!lnrpc.FileExists(d.cfg.AdminMacPath) &&
|
||||||
!fileExists(d.cfg.ReadMacPath) &&
|
!lnrpc.FileExists(d.cfg.ReadMacPath) &&
|
||||||
!fileExists(d.cfg.InvoiceMacPath) {
|
!lnrpc.FileExists(d.cfg.InvoiceMacPath) {
|
||||||
|
|
||||||
// Create macaroon files for lncli to use if they don't
|
// Create macaroon files for lncli to use if they don't
|
||||||
// exist.
|
// exist.
|
||||||
@@ -495,13 +495,13 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
|
|||||||
"--new_mac_root_key with --stateless_init to " +
|
"--new_mac_root_key with --stateless_init to " +
|
||||||
"clean up and invalidate old macaroons."
|
"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)
|
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)
|
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)
|
d.logger.Warnf(msg, "invoice", d.cfg.InvoiceMacPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-13
@@ -210,7 +210,9 @@ func (t *TLSManager) generateOrRenewCert() (*tls.Config, func(), error) {
|
|||||||
// the encrypted form.
|
// the encrypted form.
|
||||||
func (t *TLSManager) generateCertPair(keyRing keychain.SecretKeyRing) error {
|
func (t *TLSManager) generateCertPair(keyRing keychain.SecretKeyRing) error {
|
||||||
// Ensure we create TLS key and certificate if they don't exist.
|
// 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.
|
// Handle discrepencies related to the TLSEncryptKey setting.
|
||||||
return t.ensureEncryption(keyRing)
|
return t.ensureEncryption(keyRing)
|
||||||
}
|
}
|
||||||
@@ -597,18 +599,6 @@ func (t *TLSManager) deleteEphemeralSettings() {
|
|||||||
t.ephemeralCertPath = ""
|
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.
|
// IsCertExpired checks if the current TLS certificate is expired.
|
||||||
func (t *TLSManager) IsCertExpired(keyRing keychain.SecretKeyRing) (bool,
|
func (t *TLSManager) IsCertExpired(keyRing keychain.SecretKeyRing) (bool,
|
||||||
time.Time, error) {
|
time.Time, error) {
|
||||||
|
|||||||
Reference in new issue
Block a user