Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Jun 25, 2024
1 parent f8bf6c6 commit d9e9ebe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 7 additions & 5 deletions internal/cnf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func LoadCustomedMirror() map[string]string {
fPath := filepath.Join(GetVMRWorkDir(), "customed_mirrors.toml")
if ok, _ := gutils.PathIsExist(fPath); !ok {
ff := request.NewFetcher()
ff.SetUrl(DefaultReverseProxy + DefaultHostUrl + "/mirrors/customed_mirrors.toml")
ff.SetUrl(DefaultReverseProxy + strings.TrimSuffix(DefaultHostUrl, "/") + "/mirrors/customed_mirrors.toml")
s, _ := ff.GetString()
os.WriteFile(fPath, []byte(s), os.ModePerm)
}
Expand All @@ -103,7 +103,7 @@ func UseCustomedMirrorUrl(dUrl string) string {
if err != nil {
return dUrl
}
version := uu.Query().Get("version=")
version := uu.Query().Get("version")
if version == "" {
return dUrl
}
Expand All @@ -119,21 +119,23 @@ func UseCustomedMirrorUrl(dUrl string) string {
// Prepares request.Fetcher for URL.
func GetFetcher(dUrl string) (fetcher *request.Fetcher) {
// use customed mirror
oldDUrl := dUrl
dUrl = UseCustomedMirrorUrl(dUrl)

localProxy := os.Getenv(VMRLocalProxyEnv)
reverseProxy := strings.Trim(GetReverseProxyUri(dUrl, localProxy), "/")
if reverseProxy != "" {
dUrl = reverseProxy + dUrl
if reverseProxy != "" && oldDUrl == dUrl {
dUrl = reverseProxy + "/" + dUrl
}
fetcher = request.NewFetcher()

// multi-threads only for large files.
if !strings.HasSuffix(dUrl, ".json") && !strings.HasSuffix(dUrl, ".toml") {
fetcher.SetThreadNum(GetDownloadThreadNum())
}

fetcher.SetUrl(strings.Trim(dUrl, "/"))
if !strings.Contains(dUrl, "gitee.com") {
if !strings.Contains(dUrl, "gitee.com") && oldDUrl == dUrl {
// do not use proxy for gitee.
fetcher.Proxy = localProxy
}
Expand Down
6 changes: 5 additions & 1 deletion internal/cnf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cnf
import (
"os"
"path/filepath"
"strings"

"github.com/gogf/gf/v2/util/gconv"
toml "github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -128,7 +129,7 @@ func NewVMRConf() (v *VMRConf) {
os.Setenv(VMRSdkInstallationDirEnv, v.SDKIntallationDir)
}
if v.VersionHostUrl != "" {
os.Setenv(VMRHostUrlEnv, v.VersionHostUrl)
os.Setenv(VMRHostUrlEnv, strings.TrimSuffix(v.VersionHostUrl, "/"))
}
if v.ProxyUri != "" {
os.Setenv(VMRLocalProxyEnv, v.ProxyUri)
Expand All @@ -141,6 +142,9 @@ func NewVMRConf() (v *VMRConf) {
} else {
os.Setenv(VMRUseCustomedMirrorEnv, "false")
}
if v.ReverseProxy != "" {
os.Setenv(VMRReverseProxyEnv, v.ReverseProxy)
}
return v
}

Expand Down
6 changes: 6 additions & 0 deletions internal/download/sdk_file.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package download

import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/gvcgo/goutils/pkgs/gutils"
Expand Down Expand Up @@ -31,6 +33,10 @@ func NewDownloader() (d *Downloader) {
func (d *Downloader) getLocalFilePath() string {
cacheDir := cnf.GetCacheDir()
filename := filepath.Base(d.Version.Url)
// gradle: https://raw.githubusercontent.com/gvcgo/vsources/main/gradle.version.json
if d.SDKName == "gradle" && strings.Contains(filename, "?") {
filename = fmt.Sprintf("gradle-%s-all.zip", d.VersionName)
}
dd := filepath.Join(cacheDir, d.SDKName, d.VersionName)
os.MkdirAll(dd, os.ModePerm)
return filepath.Join(dd, filename)
Expand Down

0 comments on commit d9e9ebe

Please sign in to comment.