github.com/mitchellh/packer@v1.3.2/builder/vmware/common/artifact.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/hashicorp/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  	id  string
    18  	dir string
    19  	f   []string
    20  }
    21  
    22  // NewLocalArtifact returns a VMware artifact containing the files
    23  // in the given directory.
    24  func NewLocalArtifact(id string, dir string) (packer.Artifact, error) {
    25  	files := make([]string, 0, 5)
    26  	visit := func(path string, info os.FileInfo, err error) error {
    27  		if err != nil {
    28  			return err
    29  		}
    30  		if !info.IsDir() {
    31  			files = append(files, path)
    32  		}
    33  		return nil
    34  	}
    35  
    36  	if err := filepath.Walk(dir, visit); err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	return &localArtifact{
    41  		id:  id,
    42  		dir: dir,
    43  		f:   files,
    44  	}, nil
    45  }
    46  
    47  func (a *localArtifact) BuilderId() string {
    48  	return BuilderId
    49  }
    50  
    51  func (a *localArtifact) Files() []string {
    52  	return a.f
    53  }
    54  
    55  func (a *localArtifact) Id() string {
    56  	return a.id
    57  }
    58  
    59  func (a *localArtifact) String() string {
    60  	return fmt.Sprintf("VM files in directory: %s", a.dir)
    61  }
    62  
    63  func (a *localArtifact) State(name string) interface{} {
    64  	return nil
    65  }
    66  
    67  func (a *localArtifact) Destroy() error {
    68  	return os.RemoveAll(a.dir)
    69  }