From 13ffd7117180d1a3093ff291481caeb07a8b71de Mon Sep 17 00:00:00 2001 From: davy wybiral Date: Thu, 8 Aug 2019 16:13:55 -0500 Subject: [PATCH] fix windows path issue (#23) --- pkg/app/watcher.go | 4 ++-- pkg/media/library.go | 16 +++++++++------- pkg/media/video.go | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/app/watcher.go b/pkg/app/watcher.go index 624e470..74db715 100644 --- a/pkg/app/watcher.go +++ b/pkg/app/watcher.go @@ -27,10 +27,10 @@ func startWatcher(a *App) { for { select { case e := <-a.Watcher.Events: - if e.Op&removeFlags > 0 { + if e.Op&removeFlags != 0 { removeEvents[e.Name] = struct{}{} } - if e.Op&addFlags > 0 { + if e.Op&addFlags != 0 { addEvents[e.Name] = struct{}{} } // reset timer diff --git a/pkg/media/library.go b/pkg/media/library.go index e22f8ef..87fb223 100644 --- a/pkg/media/library.go +++ b/pkg/media/library.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "log" "path" + "path/filepath" "sort" "strings" "sync" @@ -60,16 +61,16 @@ func (lib *Library) Import(p *Path) error { } // Add adds a single video from a given file path. -func (lib *Library) Add(filepath string) error { +func (lib *Library) Add(fp string) error { lib.mu.Lock() defer lib.mu.Unlock() - d := path.Dir(filepath) + fp = filepath.ToSlash(fp) + d := path.Dir(fp) p, ok := lib.Paths[d] if !ok { - log.Println(d) return errors.New("media: path not found") } - n := path.Base(filepath) + n := path.Base(fp) v, err := ParseVideo(p, n) if err != nil { return err @@ -80,15 +81,16 @@ func (lib *Library) Add(filepath string) error { } // Remove removes a single video from a given file path. -func (lib *Library) Remove(filepath string) { +func (lib *Library) Remove(fp string) { lib.mu.Lock() defer lib.mu.Unlock() - d := path.Dir(filepath) + fp = filepath.ToSlash(fp) + d := path.Dir(fp) p, ok := lib.Paths[d] if !ok { return } - n := path.Base(filepath) + n := path.Base(fp) // ID is name without extension idx := strings.LastIndex(n, ".") if idx == -1 { diff --git a/pkg/media/video.go b/pkg/media/video.go index 24f89b7..9340e86 100644 --- a/pkg/media/video.go +++ b/pkg/media/video.go @@ -30,6 +30,7 @@ func ParseVideo(p *Path, name string) (*Video, error) { if err != nil { return nil, err } + defer f.Close() info, err := f.Stat() if err != nil { return nil, err