Skip to content

Commit

Permalink
WATCHER: Add watcher if event is a new dir in watched path.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cian911 committed Dec 31, 2021
1 parent e7a9d48 commit 0fc9637
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (pc *PathConsumer) Receive(path, ev string) {
log.Printf("Event Received: %s, Path: %s\n", ev, path)

// TODO: Move IsNewDirEvent to utils and call func on event struct
// TODO: If is a dir event, there should not be a file ext
e := &event.Event{
File: filepath.Base(path),
Path: path,
Expand All @@ -69,9 +70,6 @@ func (pc *PathConsumer) Receive(path, ev string) {
Operation: ev,
}

log.Printf("pc.Path: {%s}", pc.Path)
log.Printf("Event: %v", e)

if e.IsNewDirEvent() {
log.Println("Event is a new dir")

Expand Down Expand Up @@ -102,8 +100,6 @@ func (pc *PathConsumer) ProcessDirEvent(e *event.Event) {
log.Fatalf("Unable to scan files in dir event: error: %v, path: %s", err, e.Path)
}

// TODO: Copy files to destination nad only move on last file in dir that matches ext

for file := range files {
if utils.ExtractFileExt(file) == pc.Ext {
ev := event.New(file, e.Path, e.Destination, pc.Ext)
Expand Down Expand Up @@ -166,6 +162,10 @@ func (pw *PathWatcher) Observe() {
for {
select {
case event := <-watcher.Events:
if event.Op.String() == "CREATE" && utils.IsDir(event.Name) {
watcher.Add(event.Name)
}

pw.notify(event.Name, event.Op.String())
case err := <-watcher.Errors:
log.Printf("Watcher encountered an error when observing %s: %v", pw.Path, err)
Expand Down

0 comments on commit 0fc9637

Please sign in to comment.