Skip to content

Commit

Permalink
go-ipfs-config: Merge pull request ipfs#45 from ipfs/fix/is-not-exist
Browse files Browse the repository at this point in the history
make it easier to detect an uninitialized repo
  • Loading branch information
Stebalien authored Aug 29, 2019
2 parents 8c0b4cc + 47a0234 commit 3c6f994
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module github.com/ipfs/go-ipfs-config

require (
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5
github.com/ipfs/go-ipfs-util v0.0.1
github.com/libp2p/go-libp2p-core v0.0.3
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.0.4
Expand Down
2 changes: 0 additions & 2 deletions config/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJ
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10=
github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
Expand Down
13 changes: 7 additions & 6 deletions config/serialize/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import (
"github.com/ipfs/go-ipfs-config"

"github.com/facebookgo/atomicfile"
"github.com/ipfs/go-ipfs-util"
)

// ErrNotInitialized is returned when we fail to read the config because the
// repo doesn't exist.
var ErrNotInitialized = errors.New("ipfs not initialized, please run 'ipfs init'")

// ReadConfigFile reads the config from `filename` into `cfg`.
func ReadConfigFile(filename string, cfg interface{}) error {
f, err := os.Open(filename)
if err != nil {
if os.IsNotExist(err) {
err = ErrNotInitialized
}
return err
}
defer f.Close()
Expand Down Expand Up @@ -56,11 +62,6 @@ func encode(w io.Writer, value interface{}) error {

// Load reads given file and returns the read config, or error.
func Load(filename string) (*config.Config, error) {
// if nothing is there, fail. User must run 'ipfs init'
if !util.FileExists(filename) {
return nil, errors.New("ipfs not initialized, please run 'ipfs init'")
}

var cfg config.Config
err := ReadConfigFile(filename, &cfg)
if err != nil {
Expand Down

0 comments on commit 3c6f994

Please sign in to comment.