summaryrefslogtreecommitdiff
path: root/vendor/github.com/mitchellh/packer/builder/vmware/common/artifact.go
blob: e0b3e875ea39f1e7f389f65dafbaadd693e3046d (plain)
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
66
67
68
69
package common

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/hashicorp/packer/packer"
)

// BuilderId for the local artifacts
const BuilderId = "mitchellh.vmware"

// Artifact is the result of running the VMware builder, namely a set
// of files associated with the resulting machine.
type localArtifact struct {
	id  string
	dir string
	f   []string
}

// NewLocalArtifact returns a VMware artifact containing the files
// in the given directory.
func NewLocalArtifact(id string, dir string) (packer.Artifact, error) {
	files := make([]string, 0, 5)
	visit := func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.IsDir() {
			files = append(files, path)
		}
		return nil
	}

	if err := filepath.Walk(dir, visit); err != nil {
		return nil, err
	}

	return &localArtifact{
		id:  id,
		dir: dir,
		f:   files,
	}, nil
}

func (a *localArtifact) BuilderId() string {
	return BuilderId
}

func (a *localArtifact) Files() []string {
	return a.f
}

func (a *localArtifact) Id() string {
	return a.id
}

func (a *localArtifact) String() string {
	return fmt.Sprintf("VM files in directory: %s", a.dir)
}

func (a *localArtifact) State(name string) interface{} {
	return nil
}

func (a *localArtifact) Destroy() error {
	return os.RemoveAll(a.dir)
}