github.com/rothwerx/packer@v0.9.0/builder/vmware/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 // BuilderId for the local artifacts 12 const BuilderId = "mitchellh.vmware" 13 14 // Artifact is the result of running the VMware builder, namely a set 15 // of files associated with the resulting machine. 16 type localArtifact struct { 17 dir string 18 f []string 19 } 20 21 // NewLocalArtifact returns a VMware artifact containing the files 22 // in the given directory. 23 func NewLocalArtifact(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 &localArtifact{ 38 dir: dir, 39 f: files, 40 }, nil 41 } 42 43 func (a *localArtifact) BuilderId() string { 44 return BuilderId 45 } 46 47 func (a *localArtifact) Files() []string { 48 return a.f 49 } 50 51 func (*localArtifact) Id() string { 52 return "VM" 53 } 54 55 func (a *localArtifact) String() string { 56 return fmt.Sprintf("VM files in directory: %s", a.dir) 57 } 58 59 func (a *localArtifact) State(name string) interface{} { 60 return nil 61 } 62 63 func (a *localArtifact) Destroy() error { 64 return os.RemoveAll(a.dir) 65 }