diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 836b7e8f6..d4beb6208 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -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 { diff --git a/repo/fsrepo/misc.go b/repo/fsrepo/misc.go new file mode 100644 index 000000000..07730b961 --- /dev/null +++ b/repo/fsrepo/misc.go @@ -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 +}