Skip to content

Commit 2a3ab23

Browse files
author
Shanti Bouchez-Mongardé
committed
Check the datastore is writeable when initializing
1 parent dc1aafb commit 2a3ab23

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cmd/ipfs/init.go

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"encoding/base64"
5+
"path/filepath"
56
"errors"
67
"os"
78

@@ -71,6 +72,18 @@ func initCmd(c *commander.Command, inp []string) error {
7172
cfg.Datastore.Path = dspath
7273
cfg.Datastore.Type = "leveldb"
7374

75+
// Construct the data store if missing
76+
if err := os.MkdirAll(dspath, os.ModeDir); err != nil {
77+
return err
78+
}
79+
80+
// Check the directory is writeable
81+
if f, err := os.Create(filepath.Join(dspath, "._check_writeable")); err == nil {
82+
os.Remove(f.Name())
83+
} else {
84+
return errors.New("Datastore '" + dspath + "' is not writeable")
85+
}
86+
7487
cfg.Identity = config.Identity{}
7588

7689
// setup the node addresses.

0 commit comments

Comments
 (0)