2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-11-07 15:28:41 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2013-11-12 15:49:57 -05:00
|
|
|
"path/filepath"
|
2013-11-07 15:28:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// OutputDir is an interface type that abstracts the creation and handling
|
|
|
|
// of the output directory for VMware-based products. The abstraction is made
|
|
|
|
// so that the output directory can be properly made on remote (ESXi) based
|
|
|
|
// VMware products as well as local.
|
|
|
|
type OutputDir interface {
|
2013-11-08 00:18:25 -05:00
|
|
|
DirExists() (bool, error)
|
2013-11-12 15:49:57 -05:00
|
|
|
ListFiles() ([]string, error)
|
2013-11-08 00:18:25 -05:00
|
|
|
MkdirAll() error
|
2013-11-12 15:49:57 -05:00
|
|
|
Remove(string) error
|
2013-11-08 00:18:25 -05:00
|
|
|
RemoveAll() error
|
|
|
|
SetOutputDir(string)
|
2013-11-07 15:28:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// localOutputDir is an OutputDir implementation where the directory
|
|
|
|
// is on the local machine.
|
2013-11-08 00:18:25 -05:00
|
|
|
type localOutputDir struct {
|
|
|
|
dir string
|
|
|
|
}
|
2013-11-07 15:28:41 -05:00
|
|
|
|
2013-11-08 00:18:25 -05:00
|
|
|
func (d *localOutputDir) DirExists() (bool, error) {
|
|
|
|
_, err := os.Stat(d.dir)
|
2013-11-08 14:48:04 -05:00
|
|
|
return err == nil, nil
|
2013-11-07 15:28:41 -05:00
|
|
|
}
|
|
|
|
|
2013-11-12 15:49:57 -05:00
|
|
|
func (d *localOutputDir) ListFiles() ([]string, error) {
|
|
|
|
files := make([]string, 0, 10)
|
|
|
|
|
|
|
|
visit := func(path string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !info.IsDir() {
|
|
|
|
files = append(files, path)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return files, filepath.Walk(d.dir, visit)
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:18:25 -05:00
|
|
|
func (d *localOutputDir) MkdirAll() error {
|
|
|
|
return os.MkdirAll(d.dir, 0755)
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:49:57 -05:00
|
|
|
func (d *localOutputDir) Remove(path string) error {
|
|
|
|
return os.Remove(path)
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:18:25 -05:00
|
|
|
func (d *localOutputDir) RemoveAll() error {
|
|
|
|
return os.RemoveAll(d.dir)
|
2013-11-07 15:28:41 -05:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:18:25 -05:00
|
|
|
func (d *localOutputDir) SetOutputDir(path string) {
|
|
|
|
d.dir = path
|
2013-11-07 15:28:41 -05:00
|
|
|
}
|