fix windows path issue (#23)
This commit is contained in:
parent
b6bd42c860
commit
13ffd71171
3 changed files with 12 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue