Skip to content

Commit

Permalink
fix windows path issue (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
wybiral authored Aug 8, 2019
1 parent b6bd42c commit 13ffd71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/app/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions pkg/media/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"path"
"path/filepath"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/media/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13ffd71

Please sign in to comment.