packer-cn/common/floppy_config.go

54 lines
1.1 KiB
Go
Raw Normal View History

package common
import (
2016-07-26 15:42:04 -04:00
"fmt"
"os"
"path/filepath"
"strings"
2016-07-26 15:42:04 -04:00
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/template/interpolate"
)
type FloppyConfig struct {
2016-10-11 17:43:50 -04:00
FloppyFiles []string `mapstructure:"floppy_files"`
FloppyDirectories []string `mapstructure:"floppy_dirs"`
2019-09-12 08:25:22 -04:00
FloppyLabel string `mapstructure:"floppy_label"`
}
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
2016-07-26 15:42:04 -04:00
var errs []error
var err error
2016-07-26 15:42:04 -04:00
if c.FloppyFiles == nil {
c.FloppyFiles = make([]string, 0)
}
2016-07-26 15:42:04 -04:00
for _, path := range c.FloppyFiles {
2017-03-28 21:29:55 -04:00
if strings.ContainsAny(path, "*?[") {
_, err = filepath.Glob(path)
} else {
_, err = os.Stat(path)
}
if err != nil {
2016-07-26 15:42:04 -04:00
errs = append(errs, fmt.Errorf("Bad Floppy disk file '%s': %s", path, err))
}
}
if c.FloppyDirectories == nil {
c.FloppyDirectories = make([]string, 0)
}
for _, path := range c.FloppyDirectories {
2017-03-28 21:29:55 -04:00
if strings.ContainsAny(path, "*?[") {
_, err = filepath.Glob(path)
} else {
_, err = os.Stat(path)
}
if err != nil {
errs = append(errs, fmt.Errorf("Bad Floppy disk directory '%s': %s", path, err))
}
}
2016-07-26 15:42:04 -04:00
return errs
}