From 2a3ab23f1df3b4a5898d5676976fd8b68543c7d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Shanti=20Bouchez-Mongard=C3=A9?= <shanti-pub.git@mildred.fr>
Date: Fri, 26 Sep 2014 12:19:34 +0200
Subject: [PATCH] Check the datastore is writeable when initializing

---
 cmd/ipfs/init.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/cmd/ipfs/init.go b/cmd/ipfs/init.go
index 4fc581b1e..5741fe332 100644
--- a/cmd/ipfs/init.go
+++ b/cmd/ipfs/init.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"encoding/base64"
+	"path/filepath"
 	"errors"
 	"os"
 
@@ -71,6 +72,18 @@ func initCmd(c *commander.Command, inp []string) error {
 	cfg.Datastore.Path = dspath
 	cfg.Datastore.Type = "leveldb"
 
+	// Construct the data store if missing
+	if err := os.MkdirAll(dspath, os.ModeDir); 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.Identity = config.Identity{}
 
 	// setup the node addresses.
-- 
GitLab