// Listen for FS events and signal work when something changes. // Will send errors over e. func (w *Watcher) Handle(work chan bool, e chan error) { var ( evt *fsnotify.FileEvent err error ) for { select { case evt = <-w.watcher.Event: w.gw.log.Printf("Filesystem changed: %v\n", evt.String()) isNewDir := evt.IsCreate() && w.gw.isDir(evt.Name) if isNewDir || evt.IsDelete() || evt.IsRename() { err = w.WatchDirs() if err != nil { e <- err return } } select { case work <- true: // gw.log.Printf("Work queued\n") // Queued work. default: // gw.log.Printf("Work queue full\n") // Work queue full, no worries. } case err = <-w.watcher.Error: e <- err return } } }
func (p *postManager) processPostEvent(ev *fsnotify.FileEvent) { ext := strings.ToLower(filepath.Ext(ev.Name)) switch ext { case p.brog.Config.PostFileExt: case ".md": case ".markdown": case ".mkd": default: p.brog.Debug("Posts ignore files in '%s': %s", ext, ev.Name) return } if ev.IsCreate() { p.processPostCreate(ev) return } if ev.IsModify() { p.processPostModify(ev) return } if ev.IsRename() { p.processPostRename(ev) return } if ev.IsDelete() { p.processPostDelete(ev) return } p.brog.Err("FileEvent '%s' is not recognized", ev.String()) }
func (t *templateManager) processTemplateEvent(ev *fsnotify.FileEvent) { ext := strings.ToLower(filepath.Ext(ev.Name)) switch ext { case ".gohtml": case ".tmpl": default: t.brog.Debug("Templates ignore files in '%s': %s", ext, ev.Name) return } if ev.IsCreate() { // Nothing to do, all usefull templates files MUST exist at this // time or brog would not have started. return } if ev.IsModify() { t.processTemplateModify(ev) return } if ev.IsRename() || ev.IsDelete() { t.processTemplateDelete(ev) return } t.brog.Err("FileEvent '%s' is not recognized", ev.String()) }