Skip to content

Commit

Permalink
fixed in place writing not effectuated (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mristin authored Oct 1, 2018
1 parent 25d6275 commit 6c24422
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.1.1
=====
* Fixed in-place writes so that temporary file lives on the same volume

1.1.0
=====
* Added flag `-r` to remove the condition checks from the code
Expand Down
15 changes: 7 additions & 8 deletions gocontracts/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,25 +597,24 @@ func ProcessInPlace(pth string, remove bool) (err error) {
}

var tmp *os.File
tmp, err = ioutil.TempFile("", "gocontracts-"+filepath.Base(pth))
tmp, err = ioutil.TempFile(filepath.Dir(pth), "temporary-gocontracts-"+filepath.Base(pth))
if err != nil {
return
}
defer func() {
_, err = os.Stat(tmp.Name())
_, statErr := os.Stat(tmp.Name())
switch {
case err == nil:
err = os.Remove(tmp.Name())
if err != nil {
case statErr == nil:
removeErr := os.Remove(tmp.Name())
if removeErr != nil {
err = fmt.Errorf("failed to remove %s: %s", tmp.Name(), err.Error())
return
}
case os.IsNotExist(err):
case os.IsNotExist(statErr):
// Pass
err = nil

default:
err = fmt.Errorf("failed to stat %s: %s", tmp.Name(), err.Error())
err = fmt.Errorf("failed to stat %s: %s", tmp.Name(), statErr.Error())
return
}
}()
Expand Down

0 comments on commit 6c24422

Please sign in to comment.