// TenetCfgPathRecusive looks for a config file at cfgPath. If the config // file name is equal to DefaultTenetCfgPath, the func recursively searches the // parent directory until a file with that name is found. In the case that // none is found "" is retuned. func TenetCfgPathRecusive(cfgPath string) (string, error) { var err error cfgPath, err = filepath.Abs(cfgPath) if err != nil { return "", err } if _, err := os.Stat(cfgPath); os.IsNotExist(err) { dir, file := path.Split(cfgPath) if file == DefaultTenetCfgPath { if dir == "/" { // we've reached the end of the line. Fall back to default: usr, err := user.Current() if err != nil { return "", err } lHome, err := util.LingoHome() if err != nil { return "", errors.Trace(err) } defaultTenets := path.Join(usr.HomeDir, lHome, DefaultTenetCfgPath) if _, err := os.Stat(defaultTenets); err != nil { return "", err } return defaultTenets, nil } parent := path.Dir(path.Dir(dir)) return TenetCfgPathRecusive(parent + "/" + DefaultTenetCfgPath) } return "", err } return cfgPath, nil }
func (b *Binary) binPath() (string, error) { if dir := os.Getenv("LINGO_BIN"); dir != "" { return filepath.Join(dir, b.Name), nil } lHome, err := util.LingoHome() if err != nil { return "", errors.Trace(err) } return filepath.Join(lHome, "tenets", b.Name), nil }