-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
saveschema.go
39 lines (35 loc) · 845 Bytes
/
saveschema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"io/ioutil"
"os"
)
// Save the sandstorm schema files in a temporary directory, and return the path
// to that directory.
func saveSchemaFiles() (string, error) {
path, err := ioutil.TempDir("", "docker-spk-tmp-schema")
if err != nil {
return "", err
}
err = os.Mkdir(path+"/sandstorm", 0700)
if err != nil {
deleteSchemaFiles(path)
return "", err
}
for k, v := range CapnpFileMap {
err = ioutil.WriteFile(path+"/sandstorm/"+k, []byte(v), 0600)
if err != nil {
deleteSchemaFiles(path)
return "", err
}
}
return path, nil
}
// Delete the temporary path, and the schema files underneath it (as created
// by saveSchemaFiles()`.
func deleteSchemaFiles(path string) {
for k, _ := range CapnpFileMap {
os.Remove(path + "/sandstorm/" + k)
}
os.Remove(path + "/sandstorm")
os.Remove(path)
}