From afc95262198a192c8cd8d60bc4d3ce9a0e361113 Mon Sep 17 00:00:00 2001 From: Jean-Louis Huynen Date: Mon, 15 Feb 2021 16:18:57 +0100 Subject: [PATCH] add: [filerwatcher] initial work on file watcher --- d4-goclient.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/d4-goclient.go b/d4-goclient.go index 7d72f33..6a8d194 100644 --- a/d4-goclient.go +++ b/d4-goclient.go @@ -10,6 +10,7 @@ import ( "encoding/json" "flag" "fmt" + "github.com/rjeczalik/notify" "io" "io/ioutil" "log" @@ -77,6 +78,7 @@ type ( mh []byte redisInputPool *redis.Pool redisCon redis.Conn + folderfd os.File } d4params struct { @@ -91,6 +93,7 @@ type ( redisPort string redisQueue string redisDB int + folderstr string } ) @@ -347,6 +350,17 @@ func d4loadConfig(d4 *d4S) bool { if len((*d4).conf.source) < 1 { log.Fatal("Unsupported source") } + if (*d4).conf.source == "folder"{ + fstr := string(readConfFile(d4, "folder")) + if ffd , err := os.Stat(fstr); os.IsNotExist(err) { + log.Fatal("Folder does not exist") + }else{ + if !ffd.IsDir(){ + log.Fatal("Folder is not a directory") + } + } + (*d4).conf.folderstr = fstr + } if (*d4).conf.source == "d4server" { // Parse Input Redis Config tmp := string(readConfFile(d4, "redis_d4")) @@ -498,6 +512,13 @@ func setReaderWriters(d4 *d4S, force bool) bool { log.Printf("Could not create d4 Redis Descriptor %q \n", err) return false } + case "folder": + // Create a notification channel to recursively watch file event on folder + (*d4).src, err = inputreader.NewRecursiveWatcherReader(&(*d4).folderfd) + if err != nil { + log.Printf("Could not create d4 Redis Descriptor %q \n", err) + return false + } } isn, dstnet := config.IsNet((*d4).conf.destination) if isn {