diff options
Diffstat (limited to 'spooler.go')
-rw-r--r-- | spooler.go | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -4,6 +4,7 @@ import ( "github.com/fsnotify/fsnotify" "log" "os" + "fmt" ) // parse a request file and return a SCORSHmessage @@ -22,7 +23,7 @@ func parse_request(fname string) (SCORSHmsg, error) { func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { - + for { select { case event := <-watcher.Events: @@ -36,8 +37,25 @@ func spooler(watcher *fsnotify.Watcher, worker chan SCORSHmsg) { case err := <-watcher.Errors: log.Println("error:", err) } - } } +func StartSpooler(master *SCORSHmaster) error { + + watcher, err := fsnotify.NewWatcher() + + if err != nil { + return fmt.Errorf("Error creating watcher: %s\n", err) + } + + err = watcher.Add(master.Spooldir) + if err != nil { + return fmt.Errorf("Error adding folder: %s\n", err) + } + + go spooler(watcher, master.Spooler) + + return nil + +} |