-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcontainer_stub.go
58 lines (47 loc) · 1.46 KB
/
container_stub.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
50
51
52
53
54
55
56
57
58
// +build !linux
package houdini
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"code.cloudfoundry.org/garden"
)
func (container *container) setup() error {
for _, bm := range container.spec.BindMounts {
if bm.Mode == garden.BindMountModeRO {
return errors.New("read-only bind mounts are unsupported")
}
dest := filepath.Join(container.workDir, bm.DstPath)
_, err := os.Stat(dest)
if err == nil {
err = os.Remove(dest)
if err != nil {
return fmt.Errorf("failed to remove destination for bind mount: %s", err)
}
}
err = os.MkdirAll(filepath.Dir(dest), 0755)
if err != nil {
return fmt.Errorf("failed to create parent dir for bind mount: %s", err)
}
absSrc, err := filepath.Abs(bm.SrcPath)
if err != nil {
return fmt.Errorf("failed to resolve source path: %s", err)
}
// windows symlinks ("junctions") support directories, but not hard-links
// darwin hardlinks have strange restrictions
// symlinks behave reasonably similar to bind mounts on OS X (unlike Linux)
err = os.Symlink(absSrc, dest)
if err != nil {
return fmt.Errorf("failed to create hardlink for bind mount: %s", err)
}
}
return nil
}
func (container *container) cmd(spec garden.ProcessSpec) (*exec.Cmd, error) {
cmd := exec.Command(filepath.FromSlash(spec.Path), spec.Args...)
cmd.Env = append(os.Environ(), append(container.env, spec.Env...)...)
cmd.Dir = filepath.Join(container.workDir, filepath.FromSlash(spec.Dir))
return cmd, nil
}