mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
Unlinking before re-creating fixes the premature-EOF spin on unix, but Windows refuses to remove a file another handle still has open and returns a sharing violation. Because Create surfaces that error, every cache miss on a path with a live reader would have failed outright - worse than the spin it was meant to fix. Split the create behind a build tag: unix unlinks for a fresh inode, Windows keeps truncating in place and stays exposed to the spin, which is the behaviour it already had. The unix-only spec is skipped there.
16 lines
383 B
Go
16 lines
383 B
Go
//go:build windows
|
|
|
|
package cache
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/djherbis/stream"
|
|
)
|
|
|
|
// createDataFile truncates in place: Windows refuses to unlink a file another handle
|
|
// has open, and failing the create would break every miss on a path with a live reader.
|
|
func createDataFile(name string) (stream.File, error) {
|
|
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
|
}
|