From 213de86f81a61cfadf9c75b1920768495c833c95 Mon Sep 17 00:00:00 2001 From: Mohit Ranka Date: Sat, 23 Jul 2016 03:27:44 +0530 Subject: [PATCH 1/3] Fixes #130. User specified directories for 'postings', 'uids' and 'mutations' are created now, if they dont exist already. --- cmd/dgraph/main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/dgraph/main.go b/cmd/dgraph/main.go index 0cb0a586577..fc33e789fcb 100644 --- a/cmd/dgraph/main.go +++ b/cmd/dgraph/main.go @@ -44,6 +44,7 @@ import ( "github.com/dgraph-io/dgraph/uid" "github.com/dgraph-io/dgraph/worker" "github.com/dgraph-io/dgraph/x" + "os" ) var postingDir = flag.String("postings", "", "Directory to store posting lists") @@ -319,6 +320,21 @@ func main() { if *port%2 != 0 { log.Fatalf("Port should be an even number: %v", *port) } + // Create parent directories for postings, uids and mutations + var err error + err = os.MkdirAll(*postingDir, os.ModePerm) + if err != nil { + log.Fatal("Error while creating the filepath: %v", *postingDir) + return + } + err = os.MkdirAll(*mutationDir, os.ModePerm) + if err != nil { + log.Fatal("Error while creating the filepath: %v", *mutationDir) + } + err = os.MkdirAll(*uidDir, os.ModePerm) + if err != nil { + log.Fatal("Error while creating the filepath: %v", *uidDir) + } ps := new(store.Store) ps.Init(*postingDir) @@ -337,6 +353,7 @@ func main() { } posting.Init(clog) + if *instanceIdx != 0 { worker.Init(ps, nil, *instanceIdx, lenAddr) uid.Init(nil) From 5c908d3272deabaff4520e2ab594bd3ccb3e51ee Mon Sep 17 00:00:00 2001 From: Mohit Ranka Date: Sat, 23 Jul 2016 03:57:57 +0530 Subject: [PATCH 2/3] Be little more conservative with directory permissions for 'postings', uids' and 'mutations' directories and only allow user/owner process access to them. --- cmd/dgraph/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/dgraph/main.go b/cmd/dgraph/main.go index fc33e789fcb..80324275109 100644 --- a/cmd/dgraph/main.go +++ b/cmd/dgraph/main.go @@ -322,16 +322,16 @@ func main() { } // Create parent directories for postings, uids and mutations var err error - err = os.MkdirAll(*postingDir, os.ModePerm) + err = os.MkdirAll(*postingDir, 0700) if err != nil { log.Fatal("Error while creating the filepath: %v", *postingDir) return } - err = os.MkdirAll(*mutationDir, os.ModePerm) + err = os.MkdirAll(*mutationDir, 0700) if err != nil { log.Fatal("Error while creating the filepath: %v", *mutationDir) } - err = os.MkdirAll(*uidDir, os.ModePerm) + err = os.MkdirAll(*uidDir, 0700) if err != nil { log.Fatal("Error while creating the filepath: %v", *uidDir) } From 81fa0f698b267eaefe6c89ad324e221dbf33850c Mon Sep 17 00:00:00 2001 From: Mohit Ranka Date: Mon, 25 Jul 2016 01:32:46 +0530 Subject: [PATCH 3/3] Removed the unncessary return statement. Use err variable with the Fatal log message. --- cmd/dgraph/main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/dgraph/main.go b/cmd/dgraph/main.go index 80324275109..757c5cfe518 100644 --- a/cmd/dgraph/main.go +++ b/cmd/dgraph/main.go @@ -324,16 +324,15 @@ func main() { var err error err = os.MkdirAll(*postingDir, 0700) if err != nil { - log.Fatal("Error while creating the filepath: %v", *postingDir) - return + log.Fatal("Error while creating the filepath for postings: %v", err) } err = os.MkdirAll(*mutationDir, 0700) if err != nil { - log.Fatal("Error while creating the filepath: %v", *mutationDir) + log.Fatal("Error while creating the filepath for mutations: %v", err) } err = os.MkdirAll(*uidDir, 0700) if err != nil { - log.Fatal("Error while creating the filepath: %v", *uidDir) + log.Fatal("Error while creating the filepath for uids: %v", err) } ps := new(store.Store)