ModMask replaced wuth ModIgnMask. Now IN_IGNORED being watched, it makes watcher to reinstantiate.
This commit is contained in:
parent
ef27662de5
commit
60dcf2c11c
@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -143,31 +144,39 @@ func IcecastWatchPlaylist(playlistPath string, lastNSongs int) error {
|
|||||||
return errors.Wrap(err, "cannot instantiate inotify watcher")
|
return errors.Wrap(err, "cannot instantiate inotify watcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = playlistWatcher.AddWatch(playlistPath, watcher.ModMask)
|
err = playlistWatcher.AddWatch(playlistPath, watcher.ModIgnMask)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "cannot set a playlist to watch")
|
return errors.Wrap(err, "cannot set a playlist to watch")
|
||||||
}
|
}
|
||||||
|
|
||||||
playlistWatcher.WatchForMask(playlistFired, watcher.ModMask)
|
playlistWatcher.WatchForMask(playlistFired, watcher.ModIgnMask)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-playlistFired:
|
case mask := <-playlistFired:
|
||||||
lastPlayedCacheMutex.Lock()
|
if mask&syscall.IN_MODIFY > 0 {
|
||||||
songs, err := lastPlayedSongs(lastNSongs, playlistPath)
|
lastPlayedCacheMutex.Lock()
|
||||||
if err == nil && len(songs) > 0 {
|
songs, err := lastPlayedSongs(lastNSongs, playlistPath)
|
||||||
lastPlayedCache = songs
|
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)
|
songs, err := lastPlayedSongs(lastNSongs, playlistPath)
|
||||||
if err == nil && len(songs) > 0 {
|
if err == nil && len(songs) > 0 {
|
||||||
lastPlayedCache = songs
|
lastPlayedCache = songs
|
||||||
}
|
}
|
||||||
|
lastPlayedCacheMutex.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user