others.go 1005 B

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