From 8ce32e0d4c344293aaa5992733f469d057841b24 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Wed, 5 May 2021 07:51:58 +0800 Subject: [PATCH] Fix: GetAssetLocation (#974) --- common/platform/others.go | 1 - common/platform/platform_test.go | 28 ---------------------------- common/platform/windows.go | 23 ++--------------------- 3 files changed, 2 insertions(+), 50 deletions(-) diff --git a/common/platform/others.go b/common/platform/others.go index 2d7d0ceb8..a2f92c714 100644 --- a/common/platform/others.go +++ b/common/platform/others.go @@ -33,7 +33,6 @@ func GetAssetLocation(file string) string { filepath.Join("/usr/local/share/v2ray/", file), filepath.Join("/usr/share/v2ray/", file), filepath.Join("/opt/share/v2ray/", file), - file, } { if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) { continue diff --git a/common/platform/platform_test.go b/common/platform/platform_test.go index 1bff7a67f..ef0bb5495 100644 --- a/common/platform/platform_test.go +++ b/common/platform/platform_test.go @@ -10,26 +10,8 @@ import ( "github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v4/common/platform" - "github.com/v2fly/v2ray-core/v4/common/platform/filesystem" ) -func init() { - const geoipURL = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat" - - wd, err := os.Getwd() - common.Must(err) - - tempPath := filepath.Join(wd, "..", "..", "testing", "temp") - geoipPath := filepath.Join(tempPath, "geoip.dat") - - if _, err := os.Stat(geoipPath); err != nil && errors.Is(err, fs.ErrNotExist) { - common.Must(os.MkdirAll(tempPath, 0755)) - geoipBytes, err := common.FetchHTTPContent(geoipURL) - common.Must(err) - common.Must(filesystem.WriteFile(geoipPath, geoipBytes)) - } -} - func TestNormalizeEnvName(t *testing.T) { cases := []struct { input string @@ -91,16 +73,6 @@ func TestWrongErrorCheckOnOSStat(t *testing.T) { } func TestGetAssetLocation(t *testing.T) { - // Test for external geo files - wd, err := os.Getwd() - common.Must(err) - tempPath := filepath.Join(wd, "..", "..", "testing", "temp") - geoipPath := filepath.Join(tempPath, "geoip.dat") - asset := platform.GetAssetLocation(geoipPath) - if _, err := os.Stat(asset); err != nil && errors.Is(err, fs.ErrNotExist) { - t.Error("cannot find external geo file:", asset) - } - exec, err := os.Executable() common.Must(err) loc := platform.GetAssetLocation("t") diff --git a/common/platform/windows.go b/common/platform/windows.go index 08df2f46c..454a24063 100644 --- a/common/platform/windows.go +++ b/common/platform/windows.go @@ -2,12 +2,7 @@ package platform -import ( - "errors" - "io/fs" - "os" - "path/filepath" -) +import "path/filepath" func ExpandEnv(s string) string { // TODO @@ -28,19 +23,5 @@ func GetToolLocation(file string) string { func GetAssetLocation(file string) string { const name = "v2ray.location.asset" assetPath := NewEnvFlag(name).GetValue(getExecutableDir) - defPath := filepath.Join(assetPath, file) - for _, p := range []string{ - defPath, - file, - } { - if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) { - continue - } - - // asset found - return p - } - - // asset not found, let the caller throw out the error - return defPath + return filepath.Join(assetPath, file) }