use best known path method

This commit is contained in:
Brian Tiger Chow 2015-01-23 21:51:13 -08:00
parent d5e4c6a0bf
commit bb49b0191a
2 changed files with 31 additions and 2 deletions

View File

@ -30,9 +30,15 @@ func main() {
// 1. --repo flag
// 2. IPFS_PATH environment variable
// 3. default repo path
ipfsPath := config.DefaultPathRoot
var ipfsPath string
if *repoPath != "" {
ipfsPath = *repoPath
} else {
var err error
ipfsPath, err = fsrepo.BestKnownPath()
if err != nil {
log.Fatal(err)
}
}
if err := run(ipfsPath, *watchPath); err != nil {
@ -43,7 +49,7 @@ func main() {
func run(ipfsPath, watchPath string) error {
proc := process.WithParent(process.Background())
log.Printf("running IPFSWatch on %s using repo at %s...", watchPath, ipfsPath)
log.Printf("running IPFSWatch on '%s' using repo at '%s'...", watchPath, ipfsPath)
ipfsPath, err := homedir.Expand(ipfsPath)
if err != nil {

23
repo/fsrepo/misc.go Normal file
View File

@ -0,0 +1,23 @@
package fsrepo
import (
"os"
homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
"github.com/jbenet/go-ipfs/repo/config"
)
// BestKnownPath returns the best known fsrepo path. If the ENV override is
// present, this function returns that value. Otherwise, it returns the default
// repo path.
func BestKnownPath() (string, error) {
ipfsPath := config.DefaultPathRoot
if os.Getenv(config.EnvDir) != "" {
ipfsPath = os.Getenv(config.EnvDir)
}
ipfsPath, err := homedir.Expand(ipfsPath)
if err != nil {
return "", err
}
return ipfsPath, nil
}