]>
code.octet-stream.net Git - broadcaster/blob - server/files.go
b452997ef8248312f4ac139942cbddcd9f57354c
13 type FileSpec
struct {
18 type AudioFiles
struct {
27 func InitAudioFiles(path
string) {
28 files
.changeWait
= make(chan bool)
30 log
.Println("initing audio files")
35 func (r
*AudioFiles
) Refresh() {
36 entries
, err
:= os
.ReadDir(r
.path
)
38 log
.Println("couldn't read dir", r
.path
)
42 defer r
.filesMutex
.Unlock()
44 for _
, file
:= range entries
{
45 f
, err
:= os
.Open(filepath
.Join(r
.path
, file
.Name()))
47 log
.Println("couldn't open", file
.Name())
52 r
.list
= append(r
.list
, FileSpec
{Name
: file
.Name(), Hash
: hex
.EncodeToString(hash
.Sum(nil))})
54 log
.Println("Files updated", r
.list
)
55 close(files
.changeWait
)
56 files
.changeWait
= make(chan bool)
59 func (r
*AudioFiles
) Path() string {
63 func (r
*AudioFiles
) Files() []FileSpec
{
65 defer r
.filesMutex
.Unlock()
69 func (r
*AudioFiles
) Delete(filename
string) {
70 path
:= filepath
.Join(r
.path
, filepath
.Base(filename
))
71 if filepath
.Clean(r
.path
) != filepath
.Clean(path
) {
77 func (r
*AudioFiles
) WatchForChanges() ([]FileSpec
, chan bool) {
79 defer r
.filesMutex
.Unlock()
80 return r
.list
, r
.changeWait