forked from Banno/packer-post-processor-vsphere-ova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifact.go
65 lines (54 loc) · 1020 Bytes
/
artifact.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"os"
"path/filepath"
)
const BuilderId = "banno.post-processor.vsphere"
type Artifact struct {
name string
files []string
}
func NewArtifact(name string, files []string) (*Artifact, error) {
artifact := &Artifact{
name: name,
files: files,
}
for _, f := range files {
globfiles, err := filepath.Glob(f)
if err != nil {
return nil, err
}
for _, gf := range globfiles {
if _, err := os.Stat(gf); err != nil {
return nil, err
}
artifact.files = append(artifact.files, gf)
}
}
return artifact, nil
}
func (*Artifact) BuilderId() string {
return BuilderId
}
func (a *Artifact) Files() []string {
return a.files
}
func (a *Artifact) Id() string {
return ""
}
func (a *Artifact) String() string {
return fmt.Sprintf("%s", a.name)
}
func (a *Artifact) State(name string) interface{} {
return nil
}
func (a *Artifact) Destroy() error {
for _, f := range a.files {
err := os.RemoveAll(f)
if err != nil {
return err
}
}
return nil
}