2013-12-24 13:21:02 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
// LocalOutputDir is an OutputDir implementation where the directory
|
|
|
|
// is on the local machine.
|
|
|
|
type LocalOutputDir struct {
|
2013-12-24 13:22:22 -05:00
|
|
|
dir string
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) DirExists() (bool, error) {
|
2013-12-24 13:22:22 -05:00
|
|
|
_, err := os.Stat(d.dir)
|
2013-12-24 13:21:02 -05:00
|
|
|
return err == nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-12-24 13:22:22 -05:00
|
|
|
return files, filepath.Walk(d.dir, visit)
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) MkdirAll() error {
|
2013-12-24 13:22:22 -05:00
|
|
|
return os.MkdirAll(d.dir, 0755)
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) Remove(path string) error {
|
|
|
|
return os.Remove(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) RemoveAll() error {
|
2013-12-24 13:22:22 -05:00
|
|
|
return os.RemoveAll(d.dir)
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) SetOutputDir(path string) {
|
2013-12-24 13:22:22 -05:00
|
|
|
d.dir = path
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LocalOutputDir) String() string {
|
2013-12-24 13:22:22 -05:00
|
|
|
return d.dir
|
2013-12-24 13:21:02 -05:00
|
|
|
}
|