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
|
// Copyright (c) 2018-2023, 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 (
"fmt"
"os"
"github.com/sylabs/singularity/v4/pkg/build/types"
"github.com/sylabs/singularity/v4/pkg/sylog"
"github.com/sylabs/singularity/v4/pkg/util/archive"
)
// SandboxAssembler assembles a sandbox image.
type SandboxAssembler struct {
Copy bool
}
// Assemble creates a Sandbox image from a Bundle.
func (a *SandboxAssembler) Assemble(b *types.Bundle, path string) (err error) {
sylog.Infof("Creating sandbox directory...")
if _, err := os.Stat(path); err == nil {
os.RemoveAll(path)
}
if a.Copy {
sylog.Debugf("Copying sandbox from %v to %v", b.RootfsPath, path)
err := archive.CopyWithTar(b.RootfsPath+`/.`, path, false)
if err != nil {
return fmt.Errorf("copy Failed: %v", err)
}
} else {
sylog.Debugf("Moving sandbox from %v to %v", b.RootfsPath, path)
err = os.Rename(b.RootfsPath, path)
if err != nil {
return fmt.Errorf("sandbox assemble failed: %v", err)
}
}
return nil
}
|