aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/data.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-30 11:15:14 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-30 11:15:14 +0100
commit0ddbe56c19c6fc820bc7011abc22c371c9244d88 (patch)
tree838840d6345ef581f511c8ed3d603c2c741ac863 /lib/xdsconfig/data.go
parenta3e2b91e4961f2a5979b2380dce41d68ec0e03c5 (diff)
Create server data directory when not existing.
Diffstat (limited to 'lib/xdsconfig/data.go')
-rw-r--r--lib/xdsconfig/data.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/xdsconfig/data.go b/lib/xdsconfig/data.go
index 65e0fc6..b80e9a4 100644
--- a/lib/xdsconfig/data.go
+++ b/lib/xdsconfig/data.go
@@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"os"
+ "path/filepath"
common "github.com/iotbzh/xds-common/golib"
uuid "github.com/satori/go.uuid"
@@ -70,6 +71,13 @@ func serverDataWrite(file string, data ServerData) error {
sdMutex.Lock()
defer sdMutex.Unlock()
+ dir := filepath.Dir(file)
+ if !common.Exists(dir) {
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ return fmt.Errorf("Cannot create server data directory: %s", dir)
+ }
+ }
+
fd, err := os.OpenFile(file, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
defer fd.Close()
if err != nil {