sandbox: create directories
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
07181138e5
commit
228f3301f2
@ -67,7 +67,7 @@ func TestContainer(t *testing.T) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
container := sandbox.New(ctx, "/tmp/sandbox.test", "-test.v",
|
container := sandbox.New(ctx, "/usr/bin/sandbox.test", "-test.v",
|
||||||
"-test.run=TestHelperCheckContainer", "--", "check", tc.host)
|
"-test.run=TestHelperCheckContainer", "--", "check", tc.host)
|
||||||
container.Uid = 1000
|
container.Uid = 1000
|
||||||
container.Gid = 100
|
container.Gid = 100
|
||||||
@ -87,7 +87,8 @@ func TestContainer(t *testing.T) {
|
|||||||
container.
|
container.
|
||||||
Tmpfs("/tmp", 0, 0755).
|
Tmpfs("/tmp", 0, 0755).
|
||||||
Bind(os.Args[0], os.Args[0], 0).
|
Bind(os.Args[0], os.Args[0], 0).
|
||||||
Link(os.Args[0], "/tmp/sandbox.test")
|
Mkdir("/usr/bin").
|
||||||
|
Link(os.Args[0], "/usr/bin/sandbox.test")
|
||||||
// in case test has cgo enabled
|
// in case test has cgo enabled
|
||||||
var libPaths []string
|
var libPaths []string
|
||||||
if entries, err := ldd.ExecFilter(ctx,
|
if entries, err := ldd.ExecFilter(ctx,
|
||||||
|
@ -234,3 +234,31 @@ func (f *Ops) Link(target, linkName string) *Ops {
|
|||||||
*f = append(*f, &Symlink{target, linkName})
|
*f = append(*f, &Symlink{target, linkName})
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() { gob.Register(new(Mkdir)) }
|
||||||
|
|
||||||
|
// Mkdir creates a directory in the container filesystem.
|
||||||
|
type Mkdir string
|
||||||
|
|
||||||
|
func (m Mkdir) apply(*Params) error {
|
||||||
|
v := string(m)
|
||||||
|
|
||||||
|
if !path.IsAbs(v) {
|
||||||
|
return msg.WrapErr(syscall.EBADE,
|
||||||
|
fmt.Sprintf("path %q is not absolute", v))
|
||||||
|
}
|
||||||
|
|
||||||
|
target := toSysroot(v)
|
||||||
|
if err := os.MkdirAll(target, 0755); err != nil {
|
||||||
|
return msg.WrapErr(err, err.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Mkdir) Is(op Op) bool { vm, ok := op.(Mkdir); return ok && m == vm }
|
||||||
|
func (Mkdir) prefix() string { return "creating" }
|
||||||
|
func (m Mkdir) String() string { return fmt.Sprintf("directory %q", string(m)) }
|
||||||
|
func (f *Ops) Mkdir(dest string) *Ops {
|
||||||
|
*f = append(*f, Mkdir(dest))
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user