1 Star 0 Fork 0

ifa6/fresh

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
watcher.go 944 Bytes
一键复制 编辑 原始数据 按行查看 历史
package runner
import (
"os"
"path/filepath"
"strings"
"github.com/howeyc/fsnotify"
)
func watchFolder(path string) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
fatal(err)
}
go func() {
for {
select {
case ev := <-watcher.Event:
if isWatchedFile(ev.Name) {
watcherLog("sending event %s", ev)
startChannel <- ev.String()
}
case err := <-watcher.Error:
watcherLog("error: %s", err)
}
}
}()
watcherLog("Watching %s", path)
err = watcher.Watch(path)
if err != nil {
fatal(err)
}
}
func watch() {
root := root()
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if info.IsDir() && !isTmpDir(path) {
if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") {
return filepath.SkipDir
}
if isIgnoredFolder(path) {
watcherLog("Ignoring %s", path)
return filepath.SkipDir
}
watchFolder(path)
}
return err
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ifa6/fresh.git
git@gitee.com:ifa6/fresh.git
ifa6
fresh
fresh
0fa698148017

搜索帮助