github.com/rothwerx/packer@v0.9.0/builder/virtualbox/common/artifact.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 "github.com/mitchellh/packer/packer" 9 ) 10 11 // This is the common builder ID to all of these artifacts. 12 const BuilderId = "mitchellh.virtualbox" 13 14 // Artifact is the result of running the VirtualBox builder, namely a set 15 // of files associated with the resulting machine. 16 type artifact struct { 17 dir string 18 f []string 19 } 20 21 // NewArtifact returns a VirtualBox artifact containing the files 22 // in the given directory. 23 func NewArtifact(dir string) (packer.Artifact, error) { 24 files := make([]string, 0, 5) 25 visit := func(path string, info os.FileInfo, err error) error { 26 if !info.IsDir() { 27 files = append(files, path) 28 } 29 30 return err 31 } 32 33 if err := filepath.Walk(dir, visit); err != nil { 34 return nil, err 35 } 36 37 return &artifact{ 38 dir: dir, 39 f: files, 40 }, nil 41 } 42 43 func (*artifact) BuilderId() string { 44 return BuilderId 45 } 46 47 func (a *artifact) Files() []string { 48 return a.f 49 } 50 51 func (*artifact) Id() string { 52 return "VM" 53 } 54 55 func (a *artifact) String() string { 56 return fmt.Sprintf("VM files in directory: %s", a.dir) 57 } 58 59 func (a *artifact) State(name string) interface{} { 60 return nil 61 } 62 63 func (a *artifact) Destroy() error { 64 return os.RemoveAll(a.dir) 65 }