fix windows path issue (#23)

This commit is contained in:
davy wybiral 2019-08-08 16:13:55 -05:00 committed by GitHub
parent b6bd42c860
commit 13ffd71171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -27,10 +27,10 @@ func startWatcher(a *App) {
for { for {
select { select {
case e := <-a.Watcher.Events: case e := <-a.Watcher.Events:
if e.Op&removeFlags > 0 { if e.Op&removeFlags != 0 {
removeEvents[e.Name] = struct{}{} removeEvents[e.Name] = struct{}{}
} }
if e.Op&addFlags > 0 { if e.Op&addFlags != 0 {
addEvents[e.Name] = struct{}{} addEvents[e.Name] = struct{}{}
} }
// reset timer // reset timer

View file

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"path" "path"
"path/filepath"
"sort" "sort"
"strings" "strings"
"sync" "sync"
@ -60,16 +61,16 @@ func (lib *Library) Import(p *Path) error {
} }
// Add adds a single video from a given file path. // 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() lib.mu.Lock()
defer lib.mu.Unlock() defer lib.mu.Unlock()
d := path.Dir(filepath) fp = filepath.ToSlash(fp)
d := path.Dir(fp)
p, ok := lib.Paths[d] p, ok := lib.Paths[d]
if !ok { if !ok {
log.Println(d)
return errors.New("media: path not found") return errors.New("media: path not found")
} }
n := path.Base(filepath) n := path.Base(fp)
v, err := ParseVideo(p, n) v, err := ParseVideo(p, n)
if err != nil { if err != nil {
return err return err
@ -80,15 +81,16 @@ func (lib *Library) Add(filepath string) error {
} }
// Remove removes a single video from a given file path. // 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() lib.mu.Lock()
defer lib.mu.Unlock() defer lib.mu.Unlock()
d := path.Dir(filepath) fp = filepath.ToSlash(fp)
d := path.Dir(fp)
p, ok := lib.Paths[d] p, ok := lib.Paths[d]
if !ok { if !ok {
return return
} }
n := path.Base(filepath) n := path.Base(fp)
// ID is name without extension // ID is name without extension
idx := strings.LastIndex(n, ".") idx := strings.LastIndex(n, ".")
if idx == -1 { if idx == -1 {

View file

@ -30,6 +30,7 @@ func ParseVideo(p *Path, name string) (*Video, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer f.Close()
info, err := f.Stat() info, err := f.Stat()
if err != nil { if err != nil {
return nil, err return nil, err