Skip to content

Commit

Permalink
Fix panic if file was deleted before os.Lstat
Browse files Browse the repository at this point in the history
  • Loading branch information
f-blass committed May 17, 2024
1 parent dab1faf commit abcf695
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions util/configv3/load_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abcf695

Please sign in to comment.