Skip to content

Commit

Permalink
Refactor file existence check
Browse files Browse the repository at this point in the history
  • Loading branch information
haitham911 committed Oct 20, 2024
1 parent 32d5a75 commit a75fef0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions internal/exec/vendor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ func ReadAndProcessVendorConfigFile(cliConfig schema.CliConfiguration, vendorCon
}

foundVendorConfigFile := vendorConfigFile

// Look for the vendoring manifest in the current directory
if !u.FileExists(vendorConfigFile) {
foundVendorConfigFile, fileExists := u.SearchConfigFile(foundVendorConfigFile)

if !fileExists {
// Look for the vendoring manifest in the directory pointed to by the `base_path` setting in the `atmos.yaml`
pathToVendorConfig := path.Join(cliConfig.BasePath, vendorConfigFile)

Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,20 @@ func processConfigFile(
path string,
v *viper.Viper,
) (bool, error) {
if !u.FileExists(path) {
// Check if the config file exists
configPath, fileExists := u.SearchConfigFile(path)
if !fileExists {
return false, nil
}

reader, err := os.Open(path)
reader, err := os.Open(configPath)
if err != nil {
return false, err
}

defer func(reader *os.File) {
err := reader.Close()
if err != nil {
u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+path+"'. "+err.Error()))
u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+configPath+"'. "+err.Error()))
}
}(reader)

Expand Down

0 comments on commit a75fef0

Please sign in to comment.