• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang inotify.Watcher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/exp/inotify.Watcher的典型用法代码示例。如果您正苦于以下问题:Golang Watcher类的具体用法?Golang Watcher怎么用?Golang Watcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Watcher类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: waitForWatcher

func waitForWatcher(ctx context.Context, watcher *inotify.Watcher, match matcherFunc, tpl *template.Template, monitor bool) {
	defer watcher.Close()

	for {
		select {
		case <-ctx.Done(): // Timeout
			os.Exit(2)
			return

		case ev := <-watcher.Event:
			if !match(ev) {
				break
			}
			if tpl != nil {
				tpl.Execute(os.Stdout, ev)
				log.Infoln()
			} else {
				log.Infoln(ev)
			}
			// Finish if not monitoring mode.
			if !monitor {
				return
			}

		case err := <-watcher.Error:
			log.Fatal(err)
		}
	}
}
开发者ID:ceram1,项目名称:gonotify,代码行数:29,代码来源:watch.go


示例2: setFlagsWatchMode

func setFlagsWatchMode(watcher *inotify.Watcher, path string, flags string, nonroot bool) (err error) {
	watcher.RemoveWatch(path)
	setFlags(path, flags, nonroot)
	if err != nil {
		return (err)
	}
	addWatchToClosestPath(watcher, path)
	return
}
开发者ID:postfix,项目名称:paxrat,代码行数:9,代码来源:paxrat.go


示例3: setFlagsWatchMode

func setFlagsWatchMode(watcher *inotify.Watcher, path string, flags string, nonroot, nodivert bool) error {
	watcher.RemoveWatch(path)
	err := setFlags(path, flags, nonroot, nodivert)
	if err != nil {
		return err
	}
	addWatchToClosestPath(watcher, path)
	return nil
}
开发者ID:subgraph,项目名称:paxrat,代码行数:9,代码来源:paxrat.go


示例4: addWatchToClosestPath

func addWatchToClosestPath(watcher *inotify.Watcher, path string) {
	err := watcher.AddWatch(path, InotifyFlags)
	for err != nil && err.(*os.PathError).Err == syscall.ENOENT && path != "/" {
		path = filepath.Dir(path)
		if path != "/" {
			err = watcher.AddWatch(path, InotifyDirFlags)
		}
	}

}
开发者ID:postfix,项目名称:paxrat,代码行数:10,代码来源:paxrat.go


示例5: addWatch

func addWatch(from string, rec bool, hidden bool, watcher *inotify.Watcher) error {
	mask := inotify.IN_MODIFY | inotify.IN_CLOSE_WRITE | inotify.IN_MOVE |
		inotify.IN_CREATE
	walkFn := func(path string, _ os.FileInfo, err error) error {
		if !hidden && path != "." && strings.HasPrefix(path, ".") {
			return nil
		}
		return watcher.AddWatch(path, mask)
	}
	if rec {
		return filepath.Walk(from, walkFn)
	}
	return watcher.AddWatch(from, mask)
}
开发者ID:mharrys,项目名称:onchange,代码行数:14,代码来源:onchange.go


示例6: Watch

func Watch(watcher *inotify.Watcher, file os.FileInfo) error {
	if !file.IsDir() {
		return nil
	}

	incoming := path.Join(file.Name(), "incoming")

	if _, err := os.Stat(incoming); os.IsNotExist(err) {
		return err
	}
	/* Sweep existing files in there */

	if err := watcher.Watch(incoming); err != nil {
		return err
	}

	return nil
}
开发者ID:paultag,项目名称:enqueued,代码行数:18,代码来源:enqueued.go


示例7: watch

func watch(watcher *inotify.Watcher, paths []string, flag uint32, recursive, must bool) {
	log.Debugln("Watching: ", paths)

	for _, p := range paths {
		fi, err := os.Stat(p)
		if err != nil {
			if must {
				log.Fatal(err)
			}
			return
		}

		if err := watcher.AddWatch(p, flag); err != nil {
			if must {
				log.Fatal(err)
			}
			return
		}

		if !recursive || !fi.IsDir() {
			return
		}

		entries, err := ioutil.ReadDir(p)
		if err != nil {
			if must {
				log.Fatal(err)
			}
			return
		}

		var ps []string
		for _, en := range entries {
			if en.IsDir() {
				ps = append(ps, path.Join(p, en.Name()))
			}
		}
		if len(ps) == 0 {
			return
		}

		watch(watcher, ps, flag, true, false)
	}
}
开发者ID:ceram1,项目名称:gonotify,代码行数:44,代码来源:watch.go


示例8: runWatcher

// TODO: Resolve some corner cases like watches not set after create, delete, create, move
func runWatcher(watcher *inotify.Watcher) {
	LogWriter.Info("Starting paxrat watcher")
	for {
		select {
		case ev := <-watcher.Event:
			if ev.Mask == inotify.IN_CREATE {
				if _, ok := (*Conf).Settings[ev.Name]; ok {
					watcher.AddWatch(ev.Name, InotifyFlags)
					msg := fmt.Sprintf("File created: %s\n", ev.Name)
					LogWriter.Info(msg)
				}
				// Catch directory creation events for non-existent directories in executable path
			} else if ev.Mask == (inotify.IN_CREATE | inotify.IN_ISDIR) {
				for path, _ := range (*Conf).Settings {
					if strings.HasPrefix(path, ev.Name) {
						addWatchToClosestPath(watcher, path)
					}
				}
			} else if ev.Mask == inotify.IN_DELETE_SELF || ev.Mask == inotify.IN_MOVE_SELF {
				if _, ok := (*Conf).Settings[ev.Name]; ok {
					msg := fmt.Sprintf("File deleted: %s\n", ev.Name)
					LogWriter.Info(msg)
					parent := filepath.Dir(ev.Name)
					watcher.AddWatch(parent, InotifyDirFlags)
					continue
				}
			} else if ev.Mask == inotify.IN_ATTRIB {
				if _, ok := (*Conf).Settings[ev.Name]; ok {
					exists := pathExists(ev.Name)
					if !exists {
						msg := fmt.Sprintf("File deleted: %s\n", ev.Name)
						LogWriter.Info(msg)
						parent := filepath.Dir(ev.Name)
						watcher.AddWatch(parent, InotifyDirFlags)
						continue
					} else {
						msg := fmt.Sprintf("File attributes changed: %s", ev.Name)
						LogWriter.Info(msg)
					}
				}
			}
			if settings, ok := (*Conf).Settings[ev.Name]; ok {
				if ev.Mask != inotify.IN_IGNORED {
					err := setFlagsWatchMode(watcher, ev.Name, settings.Flags, settings.Nonroot)
					if err != nil {
						msg := fmt.Sprintf("watch mode setFlags error: %s", err)
						LogWriter.Err(msg)
					}
				}
			}
		case err := <-watcher.Error:
			msg := fmt.Sprintf("watch mode watcher error: %s", err)
			LogWriter.Err(msg)
		}
	}
	return
}
开发者ID:postfix,项目名称:paxrat,代码行数:58,代码来源:paxrat.go


示例9: unsetWatch

func unsetWatch(watch *inotify.Watcher, path string) {
	watch.RemoveWatch(path)
}
开发者ID:pho,项目名称:socatgun,代码行数:3,代码来源:main.go


示例10: setWatch

func setWatch(watch *inotify.Watcher, path string) {
	if err := watch.AddWatch(path, inotify.IN_MODIFY); err != nil {
		log.Println(fmt.Sprintf("Error %s setting a watcher on the config file. Changes will need a restart to become effective", err))
	}
}
开发者ID:pho,项目名称:socatgun,代码行数:5,代码来源:main.go



注:本文中的golang.org/x/exp/inotify.Watcher类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang screen.Buffer类代码示例发布时间:2022-05-28
下一篇:
Golang inotify.NewWatcher函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap