From abcf6955ec0aa4afab5985ae02f59c85ff46b874 Mon Sep 17 00:00:00 2001 From: Felix Blass Date: Fri, 17 May 2024 23:13:15 +0200 Subject: [PATCH] Fix panic if file was deleted before os.Lstat --- util/configv3/load_config.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/util/configv3/load_config.go b/util/configv3/load_config.go index ab88d147f97..ff6e72595ae 100644 --- a/util/configv3/load_config.go +++ b/util/configv3/load_config.go @@ -56,14 +56,14 @@ func GetCFConfig() (*Config, error) { // // The '.cf' directory will be read in one of the following locations on UNIX // Systems: -// 1. $CF_HOME/.cf if $CF_HOME is set -// 2. $HOME/.cf as the default +// 1. $CF_HOME/.cf if $CF_HOME is set +// 2. $HOME/.cf as the default // // The '.cf' directory will be read in one of the following locations on // Windows Systems: -// 1. CF_HOME\.cf if CF_HOME is set -// 2. HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set -// 3. USERPROFILE\.cf as the default +// 1. CF_HOME\.cf if CF_HOME is set +// 2. HOMEDRIVE\HOMEPATH\.cf if HOMEDRIVE or HOMEPATH is set +// 3. USERPROFILE\.cf as the default func LoadConfig(flags ...FlagOverride) (*Config, error) { err := removeOldTempConfigFiles() if err != nil { @@ -186,7 +186,10 @@ func removeOldTempConfigFiles() error { for _, oldTempFileName := range oldTempFileNames { fi, err := os.Lstat(oldTempFileName) // ignore if file doesn't exist anymore due to race conditions if multiple cli commands are running in parallel - if err != nil && !errors.Is(err, os.ErrNotExist) { + if err != nil { + if errors.Is(err, os.ErrNotExist) { + continue + } return err } // only delete old orphans which are not caught by the signal handler in WriteConfig