github.com/singularityware/singularity@v3.1.1+incompatible/internal/pkg/build/assemblers/assembler_sandbox.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package assemblers
     7  
     8  import (
     9  	"bytes"
    10  	"fmt"
    11  	"os"
    12  	"os/exec"
    13  
    14  	"github.com/sylabs/singularity/internal/pkg/sylog"
    15  	"github.com/sylabs/singularity/pkg/build/types"
    16  )
    17  
    18  // SandboxAssembler doesnt store anything
    19  type SandboxAssembler struct {
    20  }
    21  
    22  // Assemble creates a Sandbox image from a Bundle
    23  func (a *SandboxAssembler) Assemble(b *types.Bundle, path string) (err error) {
    24  	sylog.Infof("Creating sandbox directory...")
    25  
    26  	// move bundle rootfs to sandboxdir as final sandbox
    27  	sylog.Debugf("Moving sandbox from %v to %v", b.Rootfs(), path)
    28  	if _, err := os.Stat(path); err == nil {
    29  		os.RemoveAll(path)
    30  	}
    31  	var stderr bytes.Buffer
    32  	cmd := exec.Command("mv", b.Rootfs(), path)
    33  	cmd.Stderr = &stderr
    34  	if err = cmd.Run(); err != nil {
    35  		return fmt.Errorf("Sandbox Assemble Failed: %v: %v", err, stderr.String())
    36  	}
    37  
    38  	return nil
    39  }