LoadConfigDirCheckDuplicate is the same as the above but checks for duplciate HCL attributes TODO (HCL_DUP_KEYS_DEPRECATION): keep only LoadConfigDir once deprecation is complete
(dir string)
| 953 | // LoadConfigDirCheckDuplicate is the same as the above but checks for duplciate HCL attributes |
| 954 | // TODO (HCL_DUP_KEYS_DEPRECATION): keep only LoadConfigDir once deprecation is complete |
| 955 | func LoadConfigDirCheckDuplicate(dir string) (cfg *Config, duplicate bool, err error) { |
| 956 | f, err := os.Open(dir) |
| 957 | if err != nil { |
| 958 | return nil, false, err |
| 959 | } |
| 960 | defer f.Close() |
| 961 | |
| 962 | fi, err := f.Stat() |
| 963 | if err != nil { |
| 964 | return nil, false, err |
| 965 | } |
| 966 | if !fi.IsDir() { |
| 967 | return nil, false, fmt.Errorf("configuration path must be a directory: %q", dir) |
| 968 | } |
| 969 | |
| 970 | var files []string |
| 971 | err = nil |
| 972 | for err != io.EOF { |
| 973 | var fis []os.FileInfo |
| 974 | fis, err = f.Readdir(128) |
| 975 | if err != nil && err != io.EOF { |
| 976 | return nil, false, err |
| 977 | } |
| 978 | |
| 979 | for _, fi := range fis { |
| 980 | // Ignore directories |
| 981 | if fi.IsDir() { |
| 982 | continue |
| 983 | } |
| 984 | |
| 985 | // Only care about files that are valid to load. |
| 986 | name := fi.Name() |
| 987 | skip := true |
| 988 | if strings.HasSuffix(name, ".hcl") { |
| 989 | skip = false |
| 990 | } else if strings.HasSuffix(name, ".json") { |
| 991 | skip = false |
| 992 | } |
| 993 | if skip || isTemporaryFile(name) { |
| 994 | continue |
| 995 | } |
| 996 | |
| 997 | path := filepath.Join(dir, name) |
| 998 | files = append(files, path) |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | result := NewConfig() |
| 1003 | for _, f := range files { |
| 1004 | config, dup, err := LoadConfigFileCheckDuplicate(f) |
| 1005 | if err != nil { |
| 1006 | return nil, duplicate, fmt.Errorf("error loading %q: %w", f, err) |
| 1007 | } |
| 1008 | duplicate = duplicate || dup |
| 1009 | |
| 1010 | if result == nil { |
| 1011 | result = config |
| 1012 | } else { |
no test coverage detected
searching dependent graphs…