add: [filerwatcher] initial work on file watcher
parent
1bc27e9c65
commit
afc9526219
|
@ -10,6 +10,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/rjeczalik/notify"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -77,6 +78,7 @@ type (
|
||||||
mh []byte
|
mh []byte
|
||||||
redisInputPool *redis.Pool
|
redisInputPool *redis.Pool
|
||||||
redisCon redis.Conn
|
redisCon redis.Conn
|
||||||
|
folderfd os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
d4params struct {
|
d4params struct {
|
||||||
|
@ -91,6 +93,7 @@ type (
|
||||||
redisPort string
|
redisPort string
|
||||||
redisQueue string
|
redisQueue string
|
||||||
redisDB int
|
redisDB int
|
||||||
|
folderstr string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -347,6 +350,17 @@ func d4loadConfig(d4 *d4S) bool {
|
||||||
if len((*d4).conf.source) < 1 {
|
if len((*d4).conf.source) < 1 {
|
||||||
log.Fatal("Unsupported source")
|
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" {
|
if (*d4).conf.source == "d4server" {
|
||||||
// Parse Input Redis Config
|
// Parse Input Redis Config
|
||||||
tmp := string(readConfFile(d4, "redis_d4"))
|
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)
|
log.Printf("Could not create d4 Redis Descriptor %q \n", err)
|
||||||
return false
|
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)
|
isn, dstnet := config.IsNet((*d4).conf.destination)
|
||||||
if isn {
|
if isn {
|
||||||
|
|
Loading…
Reference in New Issue