Skip to content

Commit 1454e57

Browse files
authored
Merge pull request #386 from Unpackerr/unstable
Make folder watcher work better
2 parents 3da7307 + c20331f commit 1454e57

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ jobs:
224224
type=semver,pattern={{version}}
225225
type=semver,pattern={{major}}.{{minor}}
226226
type=semver,pattern={{major}}
227+
type=ref,enable=true,event=branch
227228
228229
- name: Set docker build-args
229230
run: >-

pkg/unpackerr/folder.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package unpackerr
55
import (
66
"errors"
77
"fmt"
8+
"log"
89
"os"
910
"path/filepath"
1011
"strings"
@@ -318,6 +319,8 @@ func mapLen(in map[string][]string) (out int) {
318319

319320
// watchFSNotify reads file system events from a channel and processes them.
320321
func (f *Folders) watchFSNotify() {
322+
defer log.Println("Folder watcher routine exited. No longer watching any folders.")
323+
321324
for {
322325
select {
323326
case err := <-f.Watcher.Error:
@@ -330,12 +333,10 @@ func (f *Folders) watchFSNotify() {
330333
}
331334

332335
f.handleFileEvent(event.Name, "f "+event.Op.String())
333-
case event, ok := <-f.Watcher.Event:
334-
if !ok {
335-
return
336-
}
337-
338-
f.handleFileEvent(event.Name(), "w "+event.Op.String())
336+
case event := <-f.Watcher.Event:
337+
f.handleFileEvent(event.Path, "w "+event.Op.String())
338+
case <-f.Watcher.Closed:
339+
return
339340
}
340341
}
341342
}
@@ -352,12 +353,18 @@ func (f *Folders) handleFileEvent(name, operation string) {
352353
// eventData.name: "new_folder"
353354
if !strings.HasPrefix(name, cnfg.Path) || name == cnfg.Path {
354355
continue // Not the configured folder for the event we just got.
355-
} else if p := filepath.Dir(name); p == cnfg.Path {
356+
}
357+
358+
if p := filepath.Dir(name); p == cnfg.Path {
356359
f.Events <- &eventData{name: filepath.Base(name), cnfg: cnfg, file: name, op: operation}
357360
} else {
358361
f.Events <- &eventData{name: filepath.Base(p), cnfg: cnfg, file: name, op: operation}
359362
}
363+
364+
return
360365
}
366+
367+
f.Debugf("Folder: Ignored event from non-configured path: %v", name)
361368
}
362369

363370
// processEvent processes the event that was received.

0 commit comments

Comments
 (0)