From 81f0158a48065d34e5770fa9899c0d0be9a369f4 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Tue, 14 Apr 2026 11:19:18 -0700 Subject: [PATCH] fix: close temp file before rename in sidecar StoreAttribute On Windows, a file apparently cannot be renamed while an open handle to it exists. The previous code used defer tempfile.Close(), which meant the handle was still open when os.Rename was called, producing: failed to rename temporary file: The process cannot access the file because it is being used by another process. Fix by closing the file explicitly before the rename. Fixes #2021 --- backend/meta/sidecar.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/meta/sidecar.go b/backend/meta/sidecar.go index 1a42c9a0..f121815c 100644 --- a/backend/meta/sidecar.go +++ b/backend/meta/sidecar.go @@ -80,13 +80,19 @@ func (s SideCar) StoreAttribute(_ *os.File, bucket, object, attribute string, va return fmt.Errorf("failed to create temporary file: %v", err) } defer os.Remove(tempfile.Name()) - defer tempfile.Close() _, err = tempfile.Write(value) if err != nil { + tempfile.Close() return fmt.Errorf("failed to write attribute: %v", err) } + // Close explicitly before rename to prevent error on Windows: + // The process cannot access the file because it is being used by another process. + if err = tempfile.Close(); err != nil { + return fmt.Errorf("failed to close temporary file: %v", err) + } + err = os.Rename(tempfile.Name(), attr) if err != nil { return fmt.Errorf("failed to rename temporary file: %v", err)