func GetCurrentVersion() (string, error) { fix := func(s string) string { if !strings.HasPrefix(s, "v") { s = "v" + s } return s } // try checking a locally running daemon first apiurl, err := util.ApiEndpoint(util.IpfsDir()) if err == nil { sh := api.NewShell(apiurl) v, _, err := sh.Version() if err == nil { return fix(v), nil } } stump.VLog("daemon check failed: %s", err) _, err = exec.LookPath("ipfs") if err != nil { return "none", nil } // try running the ipfs binary in the users path out, err := exec.Command("ipfs", "version", "-n").CombinedOutput() if err != nil { return "", fmt.Errorf("version check failed: %s - %s", string(out), err) } return fix(strings.Trim(string(out), " \n\t")), nil }
func waitForApi(ipfspath string) error { stump.VLog(" - waiting on daemon to come online") var endpoint string nloops := 15 var success bool for i := 0; i < nloops; i++ { ep, err := util.ApiEndpoint(ipfspath) if err == nil { stump.VLog(" - found api file") endpoint = ep success = true break } if !os.IsNotExist(err) { return err } time.Sleep(time.Millisecond * (100 * time.Duration(i+1))) } if !success { stump.VLog(" - no api file found, trying fallback (happens pre 0.3.8)") endpoint = "localhost:5001" } for i := 0; i < 10; i++ { _, err := net.Dial("tcp", endpoint) if err == nil { return nil } time.Sleep(time.Millisecond * (100 * time.Duration(i+1))) } return fmt.Errorf("failed to come online") }