From 31aa4bc96d161e3cb44c746a74706818eecbda81 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Sep 2024 21:53:49 +0530 Subject: [PATCH] Dont ignore err in close on atomicwrite --- tools/utils/atomic-write.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/utils/atomic-write.go b/tools/utils/atomic-write.go index 846a3f4da6f..aa22fb7c780 100644 --- a/tools/utils/atomic-write.go +++ b/tools/utils/atomic-write.go @@ -55,7 +55,11 @@ func AtomicWriteFile(path string, data io.Reader, perm os.FileMode) (err error) if err == nil { removed := false defer func() { - f.Close() + if err == nil { + err = f.Close() + } else { + f.Close() + } if !removed { os.Remove(f.Name()) removed = true