1
0

Okay, now let's return original idea of adding songs one by one.

This commit is contained in:
Alexander Andreev 2023-03-12 21:48:01 +04:00
parent 6d4a276dd8
commit d48972caa0
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -181,10 +181,7 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
pw.watcher.WatchForMask(pw.changed, watcher.ModIgnMask)
lastPlayedCache, err = icecastLastPlayedSongs(playlistPath, n)
if err != nil {
return errors.Wrap(err, "cannot instantiate last played cache")
}
lastPlayedCache = make([]Song, 0, n)
go func() {
for {
@ -192,8 +189,12 @@ func (pw *PlaylistLogWatcher) Watch(playlistPath string, n int) (err error) {
case mask := <-pw.changed:
if mask&syscall.IN_MODIFY > 0 {
lastPlayedCacheMutex.Lock()
if songs, err := icecastLastPlayedSongs(playlistPath, n); err == nil && len(songs) > 0 {
lastPlayedCache = songs
if songs, err := icecastLastPlayedSongs(playlistPath, 1); err == nil && len(songs) > 0 {
if len(lastPlayedCache) == n {
lastPlayedCache = append(lastPlayedCache[1:], songs...)
} else {
lastPlayedCache = append(lastPlayedCache, songs...)
}
}
lastPlayedCacheMutex.Unlock()
} else if mask&syscall.IN_IGNORED > 0 {