Decided to remove inotify watcher from playlist.
This commit is contained in:
parent
8587225dfc
commit
e0fa65fbd7
@ -1,12 +1,9 @@
|
|||||||
package radio
|
package radio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dwelling-radio/pkg/watcher"
|
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Playlist holds a list of paths to a song files.
|
// Playlist holds a list of paths to a song files.
|
||||||
@ -16,8 +13,6 @@ type Playlist struct {
|
|||||||
playlist []string
|
playlist []string
|
||||||
cur int
|
cur int
|
||||||
repeat bool
|
repeat bool
|
||||||
watcher *watcher.InotifyWatcher
|
|
||||||
changed chan uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPlaylist returns an instance of a Playlist struct with a loaded playlist.
|
// NewPlaylist returns an instance of a Playlist struct with a loaded playlist.
|
||||||
@ -63,34 +58,3 @@ func (p *Playlist) load() error {
|
|||||||
func (p *Playlist) Reload() error {
|
func (p *Playlist) Reload() error {
|
||||||
return p.load()
|
return p.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Playlist) Watch() (err error) {
|
|
||||||
p.watcher, err = watcher.NewInotifyWatcher()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = p.watcher.AddWatch(p.filePath, watcher.ModIgnMask)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
p.watcher.WatchForMask(p.changed, watcher.ModIgnMask)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
mask := <-p.changed
|
|
||||||
|
|
||||||
if mask&syscall.IN_MODIFY > 0 {
|
|
||||||
if err := p.load(); err != nil {
|
|
||||||
log.Fatalln("cannot reload a changed playlist:", err)
|
|
||||||
}
|
|
||||||
} else if mask&syscall.IN_IGNORED > 0 {
|
|
||||||
p.watcher.Close()
|
|
||||||
p.Watch()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user