diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 05aabe8..88cd322 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -80,8 +80,8 @@ func IcecastLastSongs(playlistPath string) []Song { lastPlayedCacheMutex.Lock() defer lastPlayedCacheMutex.Unlock() if lpcLen := len(lastPlayedCache); lpcLen > 0 { - ret := make([]Song, 0, lpcLen) - ret = append(ret, lastPlayedCache...) + ret := make([]Song, lpcLen) + copy(ret, lastPlayedCache) return ret } @@ -181,10 +181,10 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) { pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask) if lastPlayedCache == nil { - lastPlayedCache = make([]Song, 0, n) + lastPlayedCache = make([]Song, n) songs, err := icecastLastPlayedSongs(playlistPath, n) if err == nil && len(songs) > 0 { - lastPlayedCache = append(lastPlayedCache, songs...) + copy(lastPlayedCache, songs) } else if err != nil { log.Fatalln("failed to retrieve last songs:", err) }