forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloppy_config.go
52 lines (43 loc) · 1.03 KB
/
floppy_config.go
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
package common
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/hashicorp/packer/template/interpolate"
)
type FloppyConfig struct {
FloppyFiles []string `mapstructure:"floppy_files"`
FloppyDirectories []string `mapstructure:"floppy_dirs"`
}
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
var errs []error
var err error
if c.FloppyFiles == nil {
c.FloppyFiles = make([]string, 0)
}
for _, path := range c.FloppyFiles {
if strings.ContainsAny(path, "*?[") {
_, err = filepath.Glob(path)
} else {
_, err = os.Stat(path)
}
if err != nil {
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 {
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))
}
}
return errs
}