From 73735c4dbafb01fc6b5cb4d373ef70d187e56012 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Fri, 4 Aug 2017 18:28:26 +0000 Subject: [PATCH] Cleanup FIFOs on error. Signed-off-by: Lantao Liu --- io.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/io.go b/io.go index 24d927635..814ff5399 100644 --- a/io.go +++ b/io.go @@ -59,11 +59,16 @@ func NewIO(stdin io.Reader, stdout, stderr io.Writer) IOCreation { // NewIOWithTerminal creates a new io set with the provied io.Reader/Writers for use with a terminal func NewIOWithTerminal(stdin io.Reader, stdout, stderr io.Writer, terminal bool) IOCreation { - return func(id string) (*IO, error) { + return func(id string) (_ *IO, err error) { paths, err := NewFifos(id) if err != nil { return nil, err } + defer func() { + if err != nil && paths.Dir != "" { + os.RemoveAll(paths.Dir) + } + }() i := &IO{ Terminal: terminal, Stdout: paths.Out,