]>
code.octet-stream.net Git - broadcaster/blob - server/files.go
13 type FileSpec
struct {
18 type AudioFiles
struct {
27 func InitAudioFiles(path
string) {
28 files
.changeWait
= make(chan bool)
33 func (r
*AudioFiles
) Refresh() {
34 entries
, err
:= os
.ReadDir(r
.path
)
36 log
.Println("Couldn't read dir", r
.path
)
40 defer r
.filesMutex
.Unlock()
42 for _
, file
:= range entries
{
43 f
, err
:= os
.Open(filepath
.Join(r
.path
, file
.Name()))
45 log
.Println("Couldn't open", file
.Name())
50 r
.list
= append(r
.list
, FileSpec
{Name
: file
.Name(), Hash
: hex
.EncodeToString(hash
.Sum(nil))})
52 log
.Println("Files updated", r
.list
)
53 close(files
.changeWait
)
54 files
.changeWait
= make(chan bool)
57 func (r
*AudioFiles
) Path() string {
61 func (r
*AudioFiles
) Files() []FileSpec
{
63 defer r
.filesMutex
.Unlock()
67 func (r
*AudioFiles
) Delete(filename
string) {
68 path
:= filepath
.Join(r
.path
, filepath
.Base(filename
))
69 if filepath
.Clean(r
.path
) != filepath
.Clean(path
) {
75 func (r
*AudioFiles
) WatchForChanges() ([]FileSpec
, chan bool) {
77 defer r
.filesMutex
.Unlock()
78 return r
.list
, r
.changeWait