FSEvents OS X Leopard上的怪异 [英] FSEvents weirdness on OS X Leopard

查看:252
本文介绍了FSEvents OS X Leopard上的怪异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视Mac上的几个目录的文件系统事件。我想要监视的目录可能会在运行时改变,所以使用FSEvent这里是我的应用程序:
$ b

  • 创建一个全局回调函数来处理回调
  • 为每个文件夹创建一个新的FSEventStreamRef,将其与上面创建的回调相关联,并向eventStream添加一个上下文,帮助我将更改回调与此文件夹相关联。



这些东西似乎大部分都是可以工作的,但是我注意到在调用回调和将'eventPaths'的值发送到回调函数时会有一些奇怪的地方。

例如,如果我为/ Foo和/ Bar创建了StreamRef,如果我在/ Bar中添加一个文件,我的回调几乎立即被调用,但eventPaths指向一个位于/或者,我正在监视/ Foo和/ Bar,然后删除/ Bar(Foo),并且与StreamRef关联的上下文也是/ Foo的。 通过正确停止和关闭/ Bar的StreamRef)。现在我为/ Fee创建一个新的FSEventStreamRef,并与同一个回调关联。我对/ Fee所做的任何更改都不会导致回调被调用,而是改变/ Foo继续提升回调。

我在线上看到的任何示例或文档只谈谈监控一个文件夹。是什么东西与我如何将单个回调与多个FSEventStreamRefs关联?这听起来像这应该不是一个问题,虽然...



有没有人做了类似的方式,可靠地工作,或任何建议,我可能会尝试不同?

我试图做的一件事情是使用一个FSEventStreamRef并将CFArrayRef传递给我想要的所有路径,当我的表列表更改关闭,并重新创建一个新的FSEventStreamRef - 这个工作更糟糕的是,上面的解决方案

适用于我。我模仿了这些特点:$ b​​
$ b


  1. 每个流一个路径
  2. 每个路径/流一个上下文
  3. 所有流的一个回调

你能否显示失败的代码?


I want to monitor file-system events for a couple of directories on the mac. The directories I want to monitor might change at runtime, so using FSEvents here's what my app does:

  • creates a global callback function to handle callbacks
  • create a new FSEventStreamRef per folder, associating it with the callback created above and adding a context to the eventStream that helps me associate the change callback with this folder

Stuff seems to mostly work, but I've noticed some weirdness in when the callbacks are invoked and the 'eventPaths' values being sent to the callback.

For instance, if I've created StreamRefs for /Foo and /Bar, if I add a file in /Bar my callback is invoked almost immediately but the eventPaths points to a location in /Foo, and the context I associated with the StreamRef is also that of /Foo.

Or, say I'm monitoring /Foo and /Bar and then remove /Bar (by stopping and closing the StreamRef for /Bar correctly). I now create a new FSEventStreamRef for /Fee and associate with the same callback. Any changes I make to /Fee don't cause the callback to be invoked but changes to /Foo continue raising the callback.

Any example or documentation I've seen online only talks of monitoring a single folder. Is something busted with how I'm associating the single callbacks with multiple FSEventStreamRefs? It sounds like that shouldn't be a problem though...

Has anyone done something similar in a way that works reliably, or any suggestions for what I might try differently?

One thing I did attempt to do as I was experimenting with this is use a single FSEventStreamRef and pass it a CFArrayRef with all the paths I wanted, and when my watch list changes close and re-create a new FSEventStreamRef - this works even worse that the above.

解决方案

Works for me. I emulated these characteristics:

  1. One path per stream
  2. One context per path/stream
  3. One callback for all streams

Can you show the code that's failing?

这篇关于FSEvents OS X Leopard上的怪异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆