Close io when Start fails
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
18
io.go
18
io.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user