1
0

others.go 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // +build !windows
  2. package platform
  3. import (
  4. "os"
  5. "path/filepath"
  6. )
  7. func ExpandEnv(s string) string {
  8. return os.ExpandEnv(s)
  9. }
  10. func LineSeparator() string {
  11. return "\n"
  12. }
  13. func GetToolLocation(file string) string {
  14. const name = "xray.location.tool"
  15. toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
  16. return filepath.Join(toolPath, file)
  17. }
  18. // GetAssetLocation search for `file` in certain locations
  19. func GetAssetLocation(file string) string {
  20. const name = "xray.location.asset"
  21. assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
  22. defPath := filepath.Join(assetPath, file)
  23. for _, p := range []string{
  24. defPath,
  25. filepath.Join("/usr/local/share/xray/", file),
  26. filepath.Join("/usr/share/xray/", file),
  27. } {
  28. if _, err := os.Stat(p); os.IsNotExist(err) {
  29. continue
  30. }
  31. // asset found
  32. return p
  33. }
  34. // asset not found, let the caller throw out the error
  35. return defPath
  36. }