Skip to content

Commit

Permalink
Don't start the watcher if dir doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Wieku committed Jan 7, 2023
1 parent c9237f2 commit 413a533
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions launcher/beatmapdirwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/wieku/danser-go/framework/goroutines"
"log"
"os"
"path/filepath"
)

Expand All @@ -12,6 +13,13 @@ var watcher *fsnotify.Watcher
func setupWatcher(file string, callback func(event fsnotify.Event)) {
var err error

abs, _ := filepath.Abs(file)

_, err1 := os.Lstat(abs)
if err1 != nil { // Beatmap dir not found, abort
return
}

watcher, err = fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -39,8 +47,6 @@ func setupWatcher(file string, callback func(event fsnotify.Event)) {
}
})

abs, _ := filepath.Abs(file)

err = watcher.Add(abs)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 413a533

Please sign in to comment.