mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
Implement ipfs init -d (change datastore location)
This commit is contained in:
@ -29,6 +29,7 @@ func init() {
|
|||||||
cmdIpfsInit.Flag.Int("b", 4096, "number of bits for keypair")
|
cmdIpfsInit.Flag.Int("b", 4096, "number of bits for keypair")
|
||||||
cmdIpfsInit.Flag.String("p", "", "passphrase for encrypting keys")
|
cmdIpfsInit.Flag.String("p", "", "passphrase for encrypting keys")
|
||||||
cmdIpfsInit.Flag.Bool("f", false, "force overwrite of existing config")
|
cmdIpfsInit.Flag.Bool("f", false, "force overwrite of existing config")
|
||||||
|
cmdIpfsInit.Flag.String("d", "", "Change default datastore location")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initCmd(c *commander.Command, inp []string) error {
|
func initCmd(c *commander.Command, inp []string) error {
|
||||||
@ -49,6 +50,11 @@ func initCmd(c *commander.Command, inp []string) error {
|
|||||||
return errors.New("Couldn't get home directory path")
|
return errors.New("Couldn't get home directory path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dspath, ok := c.Flag.Lookup("d").Value.Get().(string)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("failed to parse datastore flag")
|
||||||
|
}
|
||||||
|
|
||||||
fi, err := os.Lstat(filename)
|
fi, err := os.Lstat(filename)
|
||||||
force, ok := c.Flag.Lookup("f").Value.Get().(bool)
|
force, ok := c.Flag.Lookup("f").Value.Get().(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -62,9 +68,11 @@ func initCmd(c *commander.Command, inp []string) error {
|
|||||||
cfg := new(config.Config)
|
cfg := new(config.Config)
|
||||||
|
|
||||||
cfg.Datastore = config.Datastore{}
|
cfg.Datastore = config.Datastore{}
|
||||||
dspath, err := u.TildeExpansion("~/.go-ipfs/datastore")
|
if len(dspath) == 0 {
|
||||||
if err != nil {
|
dspath, err = u.TildeExpansion("~/.go-ipfs/datastore")
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cfg.Datastore.Path = dspath
|
cfg.Datastore.Path = dspath
|
||||||
cfg.Datastore.Type = "leveldb"
|
cfg.Datastore.Type = "leveldb"
|
||||||
|
Reference in New Issue
Block a user