mirror of
https://github.com/getsops/sops.git
synced 2026-02-05 12:45:21 +01:00
Close tmpfile after writing (#685)
* Close tmpfile after writing Windows will not allow for deletion of a file with an open handle, close tmpfile after writing to prevent unencrypted tmpfiles out-living the execution * Update cmd/sops/edit.go Co-authored-by: Adrian Utrilla <adrianutrilla@gmail.com> * defer edited file close Co-authored-by: Adrian Utrilla <adrianutrilla@gmail.com>
This commit is contained in:
@@ -132,6 +132,9 @@ func editTree(opts editOpts, tree *sops.Tree, dataKey []byte) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, common.NewExitError(fmt.Sprintf("Could not write output file: %s", err), codes.CouldNotWriteOutputFile)
|
||||
}
|
||||
|
||||
// Close temporary file, since Windows won't delete the file unless it's closed beforehand
|
||||
defer tmpfile.Close()
|
||||
|
||||
// Compute file hash to detect if the file has been edited
|
||||
origHash, err := hashFile(tmpfile.Name())
|
||||
|
||||
Reference in New Issue
Block a user