github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/common/floppy_config.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 9 "github.com/hashicorp/packer/template/interpolate" 10 ) 11 12 type FloppyConfig struct { 13 FloppyFiles []string `mapstructure:"floppy_files"` 14 FloppyDirectories []string `mapstructure:"floppy_dirs"` 15 } 16 17 func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error { 18 var errs []error 19 var err error 20 21 if c.FloppyFiles == nil { 22 c.FloppyFiles = make([]string, 0) 23 } 24 25 for _, path := range c.FloppyFiles { 26 if strings.ContainsAny(path, "*?[") { 27 _, err = filepath.Glob(path) 28 } else { 29 _, err = os.Stat(path) 30 } 31 if err != nil { 32 errs = append(errs, fmt.Errorf("Bad Floppy disk file '%s': %s", path, err)) 33 } 34 } 35 36 if c.FloppyDirectories == nil { 37 c.FloppyDirectories = make([]string, 0) 38 } 39 40 for _, path := range c.FloppyDirectories { 41 if strings.ContainsAny(path, "*?[") { 42 _, err = filepath.Glob(path) 43 } else { 44 _, err = os.Stat(path) 45 } 46 if err != nil { 47 errs = append(errs, fmt.Errorf("Bad Floppy disk directory '%s': %s", path, err)) 48 } 49 } 50 51 return errs 52 }