Close io when Start fails

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-07-12 10:04:39 -07:00
parent 4e8943f7bb
commit 96b041e1f9
6 changed files with 145 additions and 26 deletions

18
io.go
View File

@@ -15,7 +15,14 @@ type IO struct {
Stdout string
Stderr string
closer io.Closer
closer *wgCloser
}
func (i *IO) Wait() {
if i.closer == nil {
return
}
i.closer.Wait()
}
func (i *IO) Close() error {
@@ -129,10 +136,17 @@ type ioSet struct {
type wgCloser struct {
wg *sync.WaitGroup
dir string
set []io.Closer
}
func (g *wgCloser) Wait() {
g.wg.Wait()
}
func (g *wgCloser) Close() error {
g.wg.Wait()
for _, f := range g.set {
f.Close()
}
if g.dir != "" {
return os.RemoveAll(g.dir)
}