Skip to content

Commit

Permalink
Change fsnotify paths to be absolute
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
aarol committed Dec 27, 2024
1 parent fa84935 commit 328e290
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func (reload *Reloader) WatchDirectories() {
return
}
for _, dir := range directories {
w.Add(dir)
// Path is converted to absolute path, so that fsnotify.Event also contains
// absolute paths
absPath, err := filepath.Abs(dir)
if err != nil {
reload.logError("Failed to convert path to absolute path: %s\n", err)
continue
}
w.Add(absPath)
}
}

Expand All @@ -65,9 +72,11 @@ func (reload *Reloader) WatchDirectories() {
case e := <-w.Events:
switch {
case e.Has(fsnotify.Create):
// Watch any created file/directory
if err := w.Add(e.Name); err != nil {
log.Printf("error watching %s: %s\n", e.Name, err)
dir := filepath.Dir(e.Name)
// Watch any created directory
if err := w.Add(dir); err != nil {
reload.logError("error watching %s: %s\n", e.Name, err)
continue
}
debounce(callback(path.Base(e.Name)))

Expand Down

0 comments on commit 328e290

Please sign in to comment.