github.com/aclaygray/packer@v1.3.2/post-processor/artifice/artifact.go (about) 1 package artifice 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 ) 9 10 const BuilderId = "packer.post-processor.artifice" 11 12 type Artifact struct { 13 files []string 14 } 15 16 func NewArtifact(files []string) (*Artifact, error) { 17 artifact := &Artifact{} 18 for _, f := range files { 19 globfiles, err := filepath.Glob(f) 20 if err != nil { 21 return nil, err 22 } 23 for _, gf := range globfiles { 24 if _, err := os.Stat(gf); err != nil { 25 return nil, err 26 } 27 artifact.files = append(artifact.files, gf) 28 } 29 } 30 return artifact, nil 31 } 32 33 func (a *Artifact) BuilderId() string { 34 return BuilderId 35 } 36 37 func (a *Artifact) Files() []string { 38 return a.files 39 } 40 41 func (a *Artifact) Id() string { 42 return "" 43 } 44 45 func (a *Artifact) String() string { 46 files := strings.Join(a.files, ", ") 47 return fmt.Sprintf("Created artifact from files: %s", files) 48 } 49 50 func (a *Artifact) State(name string) interface{} { 51 return nil 52 } 53 54 func (a *Artifact) Destroy() error { 55 for _, f := range a.files { 56 err := os.RemoveAll(f) 57 if err != nil { 58 return err 59 } 60 } 61 return nil 62 }