mirror of
https://github.com/versity/versitygw.git
synced 2026-04-22 21:50:29 +00:00
Merge pull request #2046 from versity/ben/windows-sidecar
fix: close temp file before rename in sidecar StoreAttribute
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user