fix: fix module cache dir

pull/172/head
kun 2021-03-01 17:52:55 +08:00
parent 504ed26fe3
commit b66f9f4b2c
1 changed files with 2 additions and 2 deletions

View File

@ -72,7 +72,6 @@ func init() {
os.Setenv("GOSUMDB", "off") os.Setenv("GOSUMDB", "off")
downloadRoot = getDownloadRoot() downloadRoot = getDownloadRoot()
os.Setenv("GOMODCACHE", downloadRoot)
} }
func main() { func main() {
@ -121,7 +120,7 @@ func getDownloadRoot() string {
GOPATH string GOPATH string
} }
if cacheDir != "" { if cacheDir != "" {
os.Setenv("GOPATH", cacheDir) os.Setenv("GOMODCACHE", filepath.Join(cacheDir, "pkg", "mod"))
return filepath.Join(cacheDir, "pkg", "mod", "cache", "download") return filepath.Join(cacheDir, "pkg", "mod", "cache", "download")
} }
if err := goJSON(&env, "go", "env", "-json", "GOPATH"); err != nil { if err := goJSON(&env, "go", "env", "-json", "GOPATH"); err != nil {
@ -131,6 +130,7 @@ func getDownloadRoot() string {
if len(list) == 0 || list[0] == "" { if len(list) == 0 || list[0] == "" {
log.Fatalf("missing $GOPATH") log.Fatalf("missing $GOPATH")
} }
os.Setenv("GOMODCACHE", filepath.Join(list[0], "pkg", "mod"))
return filepath.Join(list[0], "pkg", "mod", "cache", "download") return filepath.Join(list[0], "pkg", "mod", "cache", "download")
} }