Closed ghost closed 9 years ago
I would recommend starting with os.Getwd()
and joining it with vendor
like so:
func GetThrustDirectory() string {
wd, err := os.Getwd()
if err != nil { // Just in case
wd = "."
}
return filepath.Join(wd, "linux", "x64", common.THRUST_VERSION)
}
This could probably be removed from the os-specific files, as well, as that functionality provided by os.Getwd()
and filepath.Join()
is already cross-platform.
is user.Current() user.Homedir not cross platform?
func SetBaseDirectory(dir string) error {
if len(dir) == 0 {
usr, err := user.Current()
if err != nil {
fmt.Println(err)
}
fmt.Println(usr.HomeDir)
dir = usr.HomeDir
}
dir, err := filepath.Abs(dir)
if err != nil {
fmt.Println("Could not calculate absolute path", err)
return err
}
base = dir
return nil
}
And here is the safety check
func Run() {
if Log == nil {
InitLogger("debug")
}
if base == "" {
SetBaseDirectory("") // Default to usr.homedir.
}
@tehbilly What do you think, Working Directory or Home Directory as default, definitely however we should use path.join instead of all the windows specific "x\y\z" strings
On Linux it tries to put the vendor directory in / Hope this helps.