mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
use best known path method
This commit is contained in:
parent
d5e4c6a0bf
commit
bb49b0191a
@ -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
23
repo/fsrepo/misc.go
Normal 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user