Skip to content

Commit

Permalink
Merge pull request ejfitzgerald#5 from aminya/close-before-remove
Browse files Browse the repository at this point in the history
Close before remove
  • Loading branch information
kokulshan authored Oct 24, 2022
2 parents 715376c + ef9d441 commit 8c48b81
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions clang/clangArgumentParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ func EvaluatePreprocessedFile(buildRoot string, command *CompilerCommand) ([]byt
if err != nil {
return nil, err
}
defer f.Close()
defer func() {
f.Close()
// remove the file (clean up)
os.Remove(filename)
}()

hasher := sha256.New()
if _, err := io.Copy(hasher, f); err != nil {
Expand All @@ -105,11 +109,5 @@ func EvaluatePreprocessedFile(buildRoot string, command *CompilerCommand) ([]byt
// compute the final digest
digest := hasher.Sum(nil)

// remove the file (clean up)
err = os.Remove(filename)
if err != nil {
return nil, err
}

return digest, nil
}

0 comments on commit 8c48b81

Please sign in to comment.