"cmd/go/internal/gover"
)
-// pathExts is a cached PATHEXT list.
-var pathExts struct {
- once sync.Once
- list []string
-}
+var pathExts = sync.OnceValue(func() []string {
+ x := os.Getenv(`PATHEXT`)
+ if x == "" {
+ return []string{".com", ".exe", ".bat", ".cmd"}
+ }
-func initPathExts() {
var exts []string
- x := os.Getenv(`PATHEXT`)
- if x != "" {
- for _, e := range strings.Split(strings.ToLower(x), `;`) {
- if e == "" {
- continue
- }
- if e[0] != '.' {
- e = "." + e
- }
- exts = append(exts, e)
+ for _, e := range strings.Split(strings.ToLower(x), `;`) {
+ if e == "" {
+ continue
+ }
+ if e[0] != '.' {
+ e = "." + e
}
- } else {
- exts = []string{".com", ".exe", ".bat", ".cmd"}
+ exts = append(exts, e)
}
- pathExts.list = exts
-}
+ return exts
+})
// pathDirs returns the directories in the system search path.
func pathDirs() []string {
// described by de and info in directory dir.
// The analysis only uses the name itself; it does not run the program.
func pathVersion(dir string, de fs.DirEntry, info fs.FileInfo) (string, bool) {
- pathExts.once.Do(initPathExts)
- name, _, ok := cutExt(de.Name(), pathExts.list)
+ name, _, ok := cutExt(de.Name(), pathExts())
if !ok {
return "", false
}