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

     1  package common
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  )
     7  
     8  // LocalOutputDir is an OutputDir implementation where the directory
     9  // is on the local machine.
    10  type LocalOutputDir struct {
    11  	dir string
    12  }
    13  
    14  func (d *LocalOutputDir) DirExists() (bool, error) {
    15  	_, err := os.Stat(d.dir)
    16  	return err == nil, nil
    17  }
    18  
    19  func (d *LocalOutputDir) ListFiles() ([]string, error) {
    20  	files := make([]string, 0, 10)
    21  
    22  	visit := func(path string, info os.FileInfo, err error) error {
    23  		if err != nil {
    24  			return err
    25  		}
    26  		if !info.IsDir() {
    27  			files = append(files, path)
    28  		}
    29  		return nil
    30  	}
    31  
    32  	return files, filepath.Walk(d.dir, visit)
    33  }
    34  
    35  func (d *LocalOutputDir) MkdirAll() error {
    36  	return os.MkdirAll(d.dir, 0755)
    37  }
    38  
    39  func (d *LocalOutputDir) Remove(path string) error {
    40  	return os.Remove(path)
    41  }
    42  
    43  func (d *LocalOutputDir) RemoveAll() error {
    44  	return os.RemoveAll(d.dir)
    45  }
    46  
    47  func (d *LocalOutputDir) SetOutputDir(path string) {
    48  	d.dir = path
    49  }
    50  
    51  func (d *LocalOutputDir) String() string {
    52  	return d.dir
    53  }