forked from hofstadter-io/hof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkdir.go
49 lines (37 loc) · 742 Bytes
/
mkdir.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
40
41
42
43
44
45
46
47
48
49
package os
import (
"os"
"cuelang.org/go/cue"
hofcontext "github.com/hofstadter-io/hof/flow/context"
)
type Mkdir struct{}
func NewMkdir(val cue.Value) (hofcontext.Runner, error) {
return &Mkdir{}, nil
}
func (T *Mkdir) Run(ctx *hofcontext.Context) (interface{}, error) {
v := ctx.Value
var dir string
var err error
ferr := func() error {
ctx.CUELock.Lock()
defer func() {
ctx.CUELock.Unlock()
}()
d := v.LookupPath(cue.ParsePath("dir"))
if d.Err() != nil {
return d.Err()
} else if d.Exists() {
dir, err = d.String()
if err != nil {
return err
}
}
return nil
}()
if ferr != nil {
return nil, ferr
}
// TODO, make mode configurable
err = os.MkdirAll(dir, 0755)
return nil, err
}