navidrome/utils/cache/spread_fs_unix.go
Deluan 18f1236595 fix(cache): keep the in-place truncate on windows
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.
2026-07-26 01:28:38 -04:00

19 lines
447 B
Go

//go:build !windows
package cache
import (
"os"
"github.com/djherbis/stream"
)
// createDataFile unlinks instead of truncating, so a re-created entry gets a fresh
// inode and readers still holding the old one see its full contents.
func createDataFile(name string) (stream.File, error) {
if err := os.Remove(name); err != nil && !os.IsNotExist(err) {
return nil, err
}
return os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
}