From 60dcf2c11c607775c6a2886854cdb939af1c3d92 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 24 May 2022 23:20:19 +0400 Subject: [PATCH] ModMask replaced wuth ModIgnMask. Now IN_IGNORED being watched, it makes watcher to reinstantiate. --- internal/radio/icecast.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/radio/icecast.go b/internal/radio/icecast.go index 54d1f3e..fee6418 100644 --- a/internal/radio/icecast.go +++ b/internal/radio/icecast.go @@ -8,6 +8,7 @@ import ( "os/exec" "strings" "sync" + "syscall" "time" "github.com/pkg/errors" @@ -143,31 +144,39 @@ func IcecastWatchPlaylist(playlistPath string, lastNSongs int) error { return errors.Wrap(err, "cannot instantiate inotify watcher") } - err = playlistWatcher.AddWatch(playlistPath, watcher.ModMask) + err = playlistWatcher.AddWatch(playlistPath, watcher.ModIgnMask) if err != nil { return errors.Wrap(err, "cannot set a playlist to watch") } - playlistWatcher.WatchForMask(playlistFired, watcher.ModMask) + playlistWatcher.WatchForMask(playlistFired, watcher.ModIgnMask) go func() { for { select { - case <-playlistFired: - lastPlayedCacheMutex.Lock() - songs, err := lastPlayedSongs(lastNSongs, playlistPath) - if err == nil && len(songs) > 0 { - lastPlayedCache = songs + case mask := <-playlistFired: + if mask&syscall.IN_MODIFY > 0 { + lastPlayedCacheMutex.Lock() + songs, err := lastPlayedSongs(lastNSongs, playlistPath) + if err == nil && len(songs) > 0 { + lastPlayedCache = songs + } + lastPlayedCacheMutex.Unlock() + } else if mask&syscall.IN_IGNORED > 0 { + playlistWatcher.Close() + IcecastWatchPlaylist(playlistPath, lastNSongs) + return } - lastPlayedCacheMutex.Unlock() } } }() + lastPlayedCacheMutex.Lock() songs, err := lastPlayedSongs(lastNSongs, playlistPath) if err == nil && len(songs) > 0 { lastPlayedCache = songs } + lastPlayedCacheMutex.Unlock() return nil }