Correct style.
Shanti Bouchez-Mongardé committed
Sep 25, 2014 at 14:52 UTC
e200c089fa7f78aa06d5d5f955512be133a212a2
4 files changed
+35
-18
cmd/ipfs/config.go
+1
-1
@@ -49,7 +49,7 @@ func configCmd(c *commander.Command, inp []string) error {
49
return err
50
}
51
52
- filename, err := config.GetConfigFilePath(confdir)
52
+ filename, err := config.Filename(confdir)
53
if err != nil {
54
return err
55
}
cmd/ipfs/init.go
+2
-3
@@ -39,7 +39,7 @@ func initCmd(c *commander.Command, inp []string) error {
39
}
40
41
u.POut("initializing ipfs node at %s\n", configpath)
42
- filename, err := config.GetConfigFilePath(configpath)
42
+ filename, err := config.Filename(configpath)
43
if err != nil {
44
return errors.New("Couldn't get home directory path")
45
}
@@ -63,11 +63,10 @@ func initCmd(c *commander.Command, inp []string) error {
63
64
cfg.Datastore = config.Datastore{}
65
if len(dspath) == 0 {
66
- dspath, err = config.GetDefaultPathRoot()
66
+ dspath, err = config.DataStorePath("")
67
if err != nil {
68
return err
69
}
70
- dspath = dspath + "/datastore"
70
}
71
cfg.Datastore.Path = dspath
72
cfg.Datastore.Type = "leveldb"
cmd/ipfs/ipfs.go
+4
-4
@@ -53,7 +53,7 @@ Use "ipfs help <command>" for more information about a command.
53
}
54
55
func init() {
56
- config, err := config.GetDefaultPathRoot()
56
+ config, err := config.PathRoot()
57
if err != nil {
58
config = ""
59
}
@@ -78,7 +78,7 @@ func main() {
78
}
79
80
func localNode(confdir string, online bool) (*core.IpfsNode, error) {
81
- filename, err := config.GetConfigFilePath(confdir)
81
+ filename, err := config.Filename(confdir)
82
if err != nil {
83
return nil, err
84
}
@@ -96,14 +96,14 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
96
func getConfigDir(c *commander.Command) (string, error) {
97
conf := c.Flag.Lookup("c").Value.Get()
98
if conf == nil {
99
- return config.GetDefaultPathRoot()
99
+ return config.PathRoot()
100
}
101
confStr, ok := conf.(string)
102
if !ok {
103
return "", errors.New("failed to retrieve config flag value.")
104
}
105
if len(confStr) == 0 {
106
- return config.GetDefaultPathRoot()
106
+ return config.PathRoot()
107
}
108
109
return u.TildeExpansion(confStr)
config/config.go
+28
-10
@@ -6,6 +6,7 @@ import (
6
"encoding/base64"
7
"errors"
8
"os"
9
+ "path/filepath"
10
11
u "github.com/jbenet/go-ipfs/util"
12
)
@@ -42,27 +43,44 @@ type Config struct {
43
Bootstrap []*BootstrapPeer // local nodes's bootstrap peers
44
}
45
45
-// Return the default configuration root directory
46
-func GetDefaultPathRoot() (string, error) {
47
- dir := os.Getenv("IPFS_CONFIG_DIR")
46
+const DefaultPathRoot = "~/.go-ipfs"
47
+const DefaultConfigFile = "config"
48
+const DefaultDataStoreDirectory = "datastore"
49
+const EnvDir = "IPFS_DIR"
50
+
51
+// PathRoot returns the default configuration root directory
52
+func PathRoot() (string, error) {
53
+ dir := os.Getenv(EnvDir)
54
var err error
55
if len(dir) == 0 {
50
- dir, err = u.TildeExpansion("~/.go-ipfs")
56
+ dir, err = u.TildeExpansion(DefaultPathRoot)
57
}
58
return dir, err
59
}
60
55
-// Return the configuration file path given a configuration root directory
56
-// If the configuration root directory is empty, use the default one
57
-func GetConfigFilePath(configroot string) (string, error) {
61
+// Path returns the path `extension` relative to the configuration root. If an
62
+// empty string is provided for `configroot`, the default root is used.
63
+func Path(configroot, extension string) (string, error) {
64
if len(configroot) == 0 {
59
- dir, err := GetDefaultPathRoot()
60
- return dir+"/config", err
65
+ dir, err := PathRoot()
66
+ return filepath.Join(dir, extension), err
67
} else {
62
- return configroot+"/config", nil
68
+ return filepath.Join(configroot, extension), nil
69
}
70
}
71
72
+// DataStorePath returns the default data store path given a configuration root
73
+// (set an empty string to have the default configuration root)
74
+func DataStorePath(configroot string) (string, error) {
75
+ return Path(configroot, DefaultDataStoreDirectory);
76
+}
77
+
78
+// Filename returns the configuration file path given a configuration root
79
+// directory. If the configuration root directory is empty, use the default one
80
+func Filename(configroot string) (string, error) {
81
+ return Path(configroot, DefaultConfigFile);
82
+}
83
+
84
// DecodePrivateKey is a helper to decode the users PrivateKey
85
func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error) {
86
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)