forked from sylabs/singularity
/
assembler_sandbox.go
39 lines (32 loc) · 1.06 KB
/
assembler_sandbox.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
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package assemblers
import (
"bytes"
"fmt"
"os"
"os/exec"
"github.com/sylabs/singularity/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/build/types"
)
// SandboxAssembler doesnt store anything
type SandboxAssembler struct {
}
// Assemble creates a Sandbox image from a Bundle
func (a *SandboxAssembler) Assemble(b *types.Bundle, path string) (err error) {
sylog.Infof("Creating sandbox directory...")
// move bundle rootfs to sandboxdir as final sandbox
sylog.Debugf("Moving sandbox from %v to %v", b.Rootfs(), path)
if _, err := os.Stat(path); err == nil {
os.RemoveAll(path)
}
var stderr bytes.Buffer
cmd := exec.Command("mv", b.Rootfs(), path)
cmd.Stderr = &stderr
if err = cmd.Run(); err != nil {
return fmt.Errorf("Sandbox Assemble Failed: %v: %v", err, stderr.String())
}
return nil
}