From 91dc11b3b80efc5fbd27ac511b62166083042545 Mon Sep 17 00:00:00 2001 From: Hidetatz Yaginuma Date: Mon, 31 Jul 2023 07:48:00 +0900 Subject: [PATCH] check stdmod existence by directly looking at the directory --- stdmod.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stdmod.go b/stdmod.go index 98f39e1..1d938f0 100644 --- a/stdmod.go +++ b/stdmod.go @@ -1,25 +1,25 @@ package main import ( + "errors" "os" "path/filepath" ) -var stdmods = []string{ - "os", -} - func isstdmod(target string) bool { - for _, m := range stdmods { - if target == m { - return true - } + f := modtofile(filepath.Join(stdmoddir(), target)) + if _, err := os.Stat(f); err == nil { + return true + } else if errors.Is(err, os.ErrNotExist) { + return false + } else { + // other error. todo: handle } return false } func stdmoddir() string { - home, _ := os.UserHomeDir() + home, _ := os.UserHomeDir() // todo: handle error return filepath.Join(home, "shiba/std") }