Browse Source

Revert "Fix: GetAssetLocation for external geo files (#968)"

This reverts commit 51c8ab83
Shelikhoo 4 years ago
parent
commit
70245fd30e
3 changed files with 9 additions and 59 deletions
  1. 0 1
      common/platform/others.go
  2. 7 37
      common/platform/platform_test.go
  3. 2 21
      common/platform/windows.go

+ 0 - 1
common/platform/others.go

@@ -33,7 +33,6 @@ func GetAssetLocation(file string) string {
 		filepath.Join("/usr/local/share/v2ray/", file),
 		filepath.Join("/usr/local/share/v2ray/", file),
 		filepath.Join("/usr/share/v2ray/", file),
 		filepath.Join("/usr/share/v2ray/", file),
 		filepath.Join("/opt/share/v2ray/", file),
 		filepath.Join("/opt/share/v2ray/", file),
-		file,
 	} {
 	} {
 		if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) {
 		if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) {
 			continue
 			continue

+ 7 - 37
common/platform/platform_test.go

@@ -9,30 +9,9 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/common"
-	"github.com/v2fly/v2ray-core/v4/common/platform"
-	"github.com/v2fly/v2ray-core/v4/common/platform/filesystem"
+	. "github.com/v2fly/v2ray-core/v4/common/platform"
 )
 )
 
 
-func init() {
-	const (
-		geoipURL   = "https://raw.githubusercontent.com/v2fly/geoip/release/geoip.dat"
-		geositeURL = "https://raw.githubusercontent.com/v2fly/domain-list-community/release/dlc.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) {
 func TestNormalizeEnvName(t *testing.T) {
 	cases := []struct {
 	cases := []struct {
 		input  string
 		input  string
@@ -52,14 +31,14 @@ func TestNormalizeEnvName(t *testing.T) {
 		},
 		},
 	}
 	}
 	for _, test := range cases {
 	for _, test := range cases {
-		if v := platform.NormalizeEnvName(test.input); v != test.output {
+		if v := NormalizeEnvName(test.input); v != test.output {
 			t.Error("unexpected output: ", v, " want ", test.output)
 			t.Error("unexpected output: ", v, " want ", test.output)
 		}
 		}
 	}
 	}
 }
 }
 
 
 func TestEnvFlag(t *testing.T) {
 func TestEnvFlag(t *testing.T) {
-	if v := (platform.EnvFlag{
+	if v := (EnvFlag{
 		Name: "xxxxx.y",
 		Name: "xxxxx.y",
 	}.GetValueAsInt(10)); v != 10 {
 	}.GetValueAsInt(10)); v != 10 {
 		t.Error("env value: ", v)
 		t.Error("env value: ", v)
@@ -94,30 +73,21 @@ func TestWrongErrorCheckOnOSStat(t *testing.T) {
 }
 }
 
 
 func TestGetAssetLocation(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()
 	exec, err := os.Executable()
 	common.Must(err)
 	common.Must(err)
-	loc := platform.GetAssetLocation("t")
+
+	loc := GetAssetLocation("t")
 	if filepath.Dir(loc) != filepath.Dir(exec) {
 	if filepath.Dir(loc) != filepath.Dir(exec) {
 		t.Error("asset dir: ", loc, " not in ", exec)
 		t.Error("asset dir: ", loc, " not in ", exec)
 	}
 	}
 
 
 	os.Setenv("v2ray.location.asset", "/v2ray")
 	os.Setenv("v2ray.location.asset", "/v2ray")
 	if runtime.GOOS == "windows" {
 	if runtime.GOOS == "windows" {
-		if v := platform.GetAssetLocation("t"); v != "\\v2ray\\t" {
+		if v := GetAssetLocation("t"); v != "\\v2ray\\t" {
 			t.Error("asset loc: ", v)
 			t.Error("asset loc: ", v)
 		}
 		}
 	} else {
 	} else {
-		if v := platform.GetAssetLocation("t"); v != "/v2ray/t" {
+		if v := GetAssetLocation("t"); v != "/v2ray/t" {
 			t.Error("asset loc: ", v)
 			t.Error("asset loc: ", v)
 		}
 		}
 	}
 	}

+ 2 - 21
common/platform/windows.go

@@ -2,12 +2,7 @@
 
 
 package platform
 package platform
 
 
-import (
-	"errors"
-	"io/fs"
-	"os"
-	"path/filepath"
-)
+import "path/filepath"
 
 
 func ExpandEnv(s string) string {
 func ExpandEnv(s string) string {
 	// TODO
 	// TODO
@@ -28,19 +23,5 @@ func GetToolLocation(file string) string {
 func GetAssetLocation(file string) string {
 func GetAssetLocation(file string) string {
 	const name = "v2ray.location.asset"
 	const name = "v2ray.location.asset"
 	assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
 	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)
 }
 }