使用 kqueue() 监视目录更改的最佳方法是什么? [英] What is the optimal way to monitor changes in a directory with a kqueue()?

查看:41
本文介绍了使用 kqueue() 监视目录更改的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的:我正在 iPhone 操作系统应用程序中实现文件共享,当然这意味着文件系统监控.耶!

OK: I'm implementing File Sharing in an iPhone OS app, and of course this means filesystem monitoring. Yay!

基本上,当用户在 iTunes 中将文件操作到我的应用程序部分时,操作系统会从我可以访问的目录中复制和/或删除.因此,我需要通过像 kqueue() 这样的有效机制来监视目录的变化.

Basically, the OS copies and/or deletes from and to a directory I can access when the user manipulates files into my app's section in iTunes. Thus, I need to monitor the directory for changes presumably via an efficient mechanism like a kqueue().

我该如何实现才能知道文件已完成复制?我在想:

How do I implement this so that I know that the files have finished copying? I was thinking along the lines of:

  • 使用 kqueue() 进行监控.
  • 在事件中,开始(或重置现有)超时.
  • 超时后,开始工作.

但是有没有更好的方法来确保我不会越过操作系统的脚趾?

but is there a better way of doing it that ensures I'm not stepping over the OS's toes?

推荐答案

这只是部分答案,但可能有些用处.

This is only a partial answer, but might be somewhat useful.

  1. kqueue 机制确实可以作为一种在应用程序的 Documents 目录被修改时收到通知的方式.

  1. The kqueue mechanism indeed does work as a means to be notified when an app's Documents directory is modified.

一旦目录被修改,文件复制完成之前,就会收到通知.我在测试中观察到了这一点.

The notification comes as soon as the directory is modified and before copying a file is complete. I have observed this in testing.

遗憾的是,复制完成后没有任何形式的通知.至少,我没有找到.

Unfortunately, there is no form of notification when the copy is done. At least, none that I have found.

我希望 Apple 意识到需要有一个通知iTunes 同步"已完成,因为这似乎是一个普遍的问题.

What I hope Apple will realize is there needs to be a notification for "iTunes synch" is done, because this seems to be a general problem.

检查新文件的修改时间是否未更改的循环可能会起作用,但仅在大多数情况下有效.在某些极端情况下,iOS 可以暂停在后台执行自己的各种耗时工作.

A loop checking if the new file's modification time is not changing might work, but only most of the time. In some extreme circumstances, iOS can pause to do all kinds of time consuming work of its own in the background.

如果有办法检查特定文件是否被另一个进程打开,那么这就足够了.

If there is a way to check if a particular file is open by another process, then this would be enough.

杰夫

这篇关于使用 kqueue() 监视目录更改的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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