@cryptotaxi247 / kubo / commits / bb49b0191

use best known path method

Brian Tiger Chow committed Jan 23, 2015 at 21:51 UTC bb49b0191a0feef9ba4948cd03192d9359bb1a7a
2 files changed +31 -2
cmd/ipfswatch/main.go
+8 -2
@@ -30,9 +30,15 @@ func main() {
30 // 1. --repo flag
31 // 2. IPFS_PATH environment variable
32 // 3. default repo path
33 - ipfsPath := config.DefaultPathRoot
33 + var ipfsPath string
34 if *repoPath != "" {
35 ipfsPath = *repoPath
36 + } else {
37 + var err error
38 + ipfsPath, err = fsrepo.BestKnownPath()
39 + if err != nil {
40 + log.Fatal(err)
41 + }
42 }
43
44 if err := run(ipfsPath, *watchPath); err != nil {
@@ -43,7 +49,7 @@ func main() {
49 func run(ipfsPath, watchPath string) error {
50
51 proc := process.WithParent(process.Background())
46 - log.Printf("running IPFSWatch on %s using repo at %s...", watchPath, ipfsPath)
52 + log.Printf("running IPFSWatch on '%s' using repo at '%s'...", watchPath, ipfsPath)
53
54 ipfsPath, err := homedir.Expand(ipfsPath)
55 if err != nil {
repo/fsrepo/misc.go new
+23
@@ -0,0 +1,23 @@
1 +package fsrepo
2 +
3 +import (
4 + "os"
5 +
6 + homedir "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
7 + "github.com/jbenet/go-ipfs/repo/config"
8 +)
9 +
10 +// BestKnownPath returns the best known fsrepo path. If the ENV override is
11 +// present, this function returns that value. Otherwise, it returns the default
12 +// repo path.
13 +func BestKnownPath() (string, error) {
14 + ipfsPath := config.DefaultPathRoot
15 + if os.Getenv(config.EnvDir) != "" {
16 + ipfsPath = os.Getenv(config.EnvDir)
17 + }
18 + ipfsPath, err := homedir.Expand(ipfsPath)
19 + if err != nil {
20 + return "", err
21 + }
22 + return ipfsPath, nil
23 +}