1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 18:13:54 +08:00

fix(ipfs2/init) datastore

This commit is contained in:
Brian Tiger Chow
2014-11-04 19:09:47 -08:00
committed by Juan Batiz-Benet
parent 542c2a2da3
commit 62fd9166ce

View File

@ -86,28 +86,11 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
}
cfg := new(config.Config)
if len(dspath) == 0 {
dspath, err = config.DataStorePath("")
if err != nil {
return err
}
}
cfg.Datastore = config.Datastore{
Path: dspath,
Type: "leveldb",
}
// Construct the data store if missing
if err := os.MkdirAll(dspath, os.ModePerm); err != nil {
ds, err := datastoreConfig(dspath)
if err != nil {
return err
}
// Check the directory is writeable
if f, err := os.Create(filepath.Join(dspath, "._check_writeable")); err == nil {
os.Remove(f.Name())
} else {
return errors.New("Datastore '" + dspath + "' is not writeable")
}
cfg.Datastore = ds
cfg.Identity = config.Identity{}
@ -162,3 +145,30 @@ func doInit(configRoot string, dspath string, force bool, nBitsForKeypair int) e
}
return nil
}
func datastoreConfig(dspath string) (config.Datastore, error) {
ds := config.Datastore{}
if len(dspath) == 0 {
var err error
dspath, err = config.DataStorePath("")
if err != nil {
return ds, err
}
}
ds.Path = dspath
ds.Type = "leveldb"
// Construct the data store if missing
if err := os.MkdirAll(dspath, os.ModePerm); err != nil {
return ds, err
}
// Check the directory is writeable
if f, err := os.Create(filepath.Join(dspath, "._check_writeable")); err == nil {
os.Remove(f.Name())
} else {
return ds, errors.New("Datastore '" + dspath + "' is not writeable")
}
return ds, nil
}