Skip to content

Commit

Permalink
You can't call Abort twice
Browse files Browse the repository at this point in the history
  • Loading branch information
kentquirk committed Dec 24, 2018
1 parent 7ce4cd5 commit 2cba91c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/rewriter/rewriter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rewriter

import (
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -89,15 +90,23 @@ func (f *File) Close() error {
}

// Abort deletes the temp file and closes the input file without modification.
// It is an error to call this more than once, or after calling Close()
// as it won't do what you wanted it to.
func (f *File) Abort() error {
if f.input == nil || f.output == nil || f.tempfile == "" {
return fmt.Errorf("unable to abort %s -- already closed", f.filename)
}
err := f.input.Close()
f.input = nil
if err != nil {
return err
}
err = f.output.Close()
f.output = nil
if err != nil {
return err
}
err = os.Remove(f.tempfile)
f.tempfile = ""
return err
}

0 comments on commit 2cba91c

Please sign in to comment.