问题标签 [fsevents]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
834 浏览

macos - 使用 NSFileManager 获取复制文件的修改日期

我正在使用 NSFileManager 的 attributesOfItemAtPath 来计算文件在 OS X 中的最后修改日期。虽然这有效,但在许多情况下,文件修改日期的行为并不像我预期的那样。例如:如果我复制 2009 年创建的文件并将其粘贴到新目录中,它会保留原始文件的创建和修改日期。

为了将问题放在上下文中,我正在使用 FSEvents API 监视文件系统事件。这提醒我目录级别发生了更改。为了检测该特定目录中哪个文件发生了更改,我遍历每个文件并检查其修改日期。这适用于新创建的文件,但不适用于从文件系统其他地方复制的文件。

是否有我可以访问的低级 API 以获取有关特定文件的更多信息?如果不是,在文件级别确定特定文件系统更改的最佳方法是什么?

0 投票
1 回答
2398 浏览

cocoa - 是否可以使用 FSEvents 获取文件夹已移动的通知?

我正在使用 FSEvents API 来获取我正在跟踪的本地目录中的更改通知。

是否可以使用 FSEvents 或其他任何方法获得监视目录已移动到磁盘上另一个位置的通知?

更新:

这是我到目前为止的代码,我现在尝试将 kFSEventStreamCreateFlagWatchRoot 标志与 FSEventStreamCreate 一起使用来获取根更改通知,到目前为止没有成功。

0 投票
1 回答
1037 浏览

objective-c - 是否有一个用于文件系统事件/kqueue 的好的 objc 库包装器来为我处理递归监视?

我想编写一个 OSX (Snow Leopard) 应用程序,当特定目录中的文件发生更改时接收通知,并且我想访问已更改的特定文件的路径。

我知道我可以使用File System Events或来做到这一点kqueue。前者没有提供更改特定文件的详细信息(要求我构建我正在观看的目录的快照,然后扫描它以找出更改的文件)。后者不支持递归监视(要求我递归地将监视添加到父目录中的每个文件和目录)。

我已经查找了为我处理快照/递归乐趣的库,但找不到任何库。UKKQueue看起来像是低级kqueue东西的一个很好的包装器,但似乎不做递归。对GTMFileSystemKQueue. SCEvents看起来像是一个很好的包装器,File System Events但似乎无法处理找出更改的特定文件。

是否有一个库可以满足我的要求并且适合这些技术中的任何一种的 objc 项目?

0 投票
5 回答
8639 浏览

objective-c - NSTableView 中的 reloadData 但保留当前选择

我有一个NSTableView显示目录的内容。我关注 FSEvents,每次收到事件时,我都会重新加载我的表格视图。不幸的是,当前选择随即消失。有没有办法避免这种情况?

0 投票
1 回答
1499 浏览

cocoa - FSEvents 神秘地无法在某些文件夹中传递事件

这让我很生气,我不确定我知道如何调试它。

我正在使用 Mac FSEvents API 来监视文件系统上的给定文件夹。但是,有时,某些文件夹会停止发送任何通知事件。到目前为止,这只发生在 ~/Dropbox 中的文件夹中,并且只影响了我的应用程序的少数用户(并且也经常影响我)。

疯狂的部分是“治愈”文件系统的方法是:

运行这些命令后,文件夹解开并开始发送事件!需要几次尝试才能找出哪个父文件夹是罪魁祸首,但它始终是 Dropbox 中的某个文件夹。(退出 Dropbox 或重新启动并不能解决问题。)

我在我的代码中没有做任何特别的事情。使用以下命令开始监控:

回调看起来像这样(没关系):

发生在 10.6 和 10.7 上。没有像 FileVault 这样的花哨的东西处于活动状态。

这在我看来确实像一个操作系统错误,但我没有在网络上发现任何关于此问题的提及。

问题是:

1)你有没有经历过这样的事情?有什么发现吗?

2) 在使用技术支持事件之前,进一步诊断此问题的步骤是什么?

0 投票
1 回答
834 浏览

cocoa - 更改 fsevents 中的 pathsToWatch

我已经使用 fsevents 建立了一个观察者机制。它的要点是每次在文件夹 X 中创建文件时,我都希望运行一个函数。它现在运行良好,但我需要能够改变它正在观看的路径。这是设置代码:

我首先尝试停止 FSEventStream,然后再次启动它,但再次exc_bad_access调用时我得到了一个FSEventStreamCreate

还尝试pathsToWatch即时调整阵列,但这也导致了错误的访问错误。

有一个更好的方法吗?

0 投票
1 回答
2361 浏览

objective-c - 在没有 fsevent 的情况下监视 OSX 中的目录更改

是否有替代 fsevent 或某种包装器的方法?

我正在尝试监视特定文件夹以更改具有特定扩展名的文件。

0 投票
2 回答
4327 浏览

objective-c - tracking file renaming/deleting with FSEvents on Lion

I'm trying to use FSEvents to detect when files were added/removed from a specific folder. For the moment, I implemented a simple wrapper around FSEvents, and it works fine : I get all the events.

BUT the problem I have now is that when I rename a file in the Finder, I catch 2 distinct events : the first one of type "renamed" with the old file name, and another one with "renamed" and the new filename. The event ids are different between both calls.

So, how am I supposed to know which "renamed" event contains the old name, and which event contains the old one ?? I tried looking in the documentation, but unfortunately, kFSEventStreamEventFlagItemRenamed is not documented ... it seems new in Lion.

PS: the only way I could think of was : on a renamed event, I check my UI to see if I have an item corresponding to the event path. If so, I flag it for renaming. If not, I check if an item was flagged for renaming, and if so, then I rename it to the new event path. But I really don't like this idea ...

Edit: Ok, I imlemented something along the line of my "PS" : I noticed that when renaming something, the ids of the 2 events are consecutives, so that with the id of the event containing the new name, I can get the event containing the old name. I simply use a little dictionnary in my interface to store ids and associated paths in the case of a "renamed" event.

Anyway, I can now catch rename events, and even move events : when you move a file, it's a "renamed" event which is caught by the FSEventStream ...

But, I still have one last problem : deleting. When I delete something, it's moved to the recycle bin : I receive a "renamed" event. But the problem is that I don't receive the second rename event. Only a "modified" event on the .DS_Store file. I think this file is used by the Finder to know which files are in the bin, etc. So I could check modification to this file, and get the last "renamed" event to detect that a file was sent to the bin. But I'm using TotalFinder which uses Asepsis, which modifies the way the Finder stores .DS_Store files : I no longer receive "modified" on this. To sumarize : I can't detect when a file is sent to the bin ...

Any idea how I can do that ? Maybe use something else than FSEvents to catch only this event ?

0 投票
4 回答
5993 浏览

ruby-on-rails - Guard 看不到文件更新

我正在使用此设置开发自定义引擎。

我已经创建了引擎

然后我添加了rspec-railsguard-rspec作为开发依赖项

在我的 gemspec 文件中。

当我同时运行rspecrake spec(有或没有bundle exec)我的规格运行良好。但是,当我运行guard命令时,它第一次运行所有规范,然后它什么也不做。它不会检测到整个应用程序中的任何文件更改。

Guardfile 像往常一样生成guard init spec,这里是它的内容

如果我在守卫运行的情况下保持一个外壳打开,而我从另一个外壳做touch app/my_model.rb任何事情都不会发生。Guardfile 中列出的所有其他文件(模式)都相同。

有没有办法调试这类问题?

更新 我创建了一个新项目(一个rails)并用这个安装了guard-shell gemGuardfile

即使在这种情况下,如果我编辑任何文件,也不会发生任何事情。我开始认为问题可能出在其他地方,也许在rb-fsevents宝石中。我可以检查什么?

0 投票
1 回答
1218 浏览

objective-c - 在 FSEventStreamCreate 中声明回调函数

有几个使用 FSEvent 来监听文件系统变化的例子。

如何侦听文件系统更改 MAC - kFSEventStreamCreateFlagWatchRoot

OS X Leopard 上的 FSEvents 怪异

当使用它们创建事件时,FSEventStreamCreate它们似乎都可以很好地传递回调项。没有参数或任何东西,只是&feCallback. 基本上,如果有意义的话,它们似乎传递的是变量而不是函数。

但是Use of Undeclared identifier当我尝试这样做时出现错误。是什么赋予了?

然后有回调函数:

我想要一些示例代码来让开源帮助器对象在这里工作:https ://bitbucket.org/boredzo/fs-notifier/overview

但同样的事情。它有以下方法:

- (id) initWithCallback:(FSEventStreamCallback)newCallback path:(NSString *)newPath;

newCallback由于上述错误,我无法通过它。