From 6d03ddede4f86e67d25dbcd105e4d9bad66de3fa Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Thu, 6 Oct 2022 18:48:38 -0500 Subject: [PATCH] fix: cosmovisor: isolate and return masked errors that are not non-existence errors (#13470) Enumerates and improves on the error checking for non-existance errors to clearly return unhandled errors such as access restrictions, unaccessible volumes etc, when trying to download binaries. The prior code assumed that either the file existed or the only error to be returned would be about the file not existing, yet this isn't always true. Fixes #13469 --- cosmovisor/upgrade.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cosmovisor/upgrade.go b/cosmovisor/upgrade.go index e31ee15819..69c17a8fae 100644 --- a/cosmovisor/upgrade.go +++ b/cosmovisor/upgrade.go @@ -33,8 +33,15 @@ func UpgradeBinary(logger *zerolog.Logger, cfg *Config, info upgradetypes.Plan) } // if the dir is there already, don't download either - if _, err := os.Stat(cfg.UpgradeDir(info.Name)); !os.IsNotExist(err) { + switch fi, err := os.Stat(cfg.UpgradeDir(info.Name)); { + case fi != nil: // The directory exists, do not overwrite. return errors.New("upgrade dir already exists, won't overwrite") + + case os.IsNotExist(err): // In this case the directory doesn't exist, continue below. + // Do nothing and we shall download the binary down below. + + default: // Otherwise an unexpected error + return fmt.Errorf("unhandled error: %w", err) } // If not there, then we try to download it... maybe