监视目录更改的最佳方法是什么

监视目录更改的最佳方法是什么

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

问题描述

OK:我在iPhone操作系统应用程序中实现文件共享,当然这意味着文件系统监控。 Yay!



基本上,当用户在iTunes中将文件操作到我的应用程序部分时,操作系统会拷贝和/或删除目录。因此,我需要通过一个有效的机制来监视目录,例如 kqueue()



我是否实现这一点,以便我知道文件已经完成复制?我正在考虑以下方面:




  • 使用 kqueue() / li>
  • 在事件中,启动(或重置现有的)超时。

  • 当超时时,请做工。



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

解决方案

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


  1. 作为修改应用程序的Documents目录时通知的一种方法。


  2. 只要目录被修改,并且在复制文件之前完成。我已经在测试中观察到了这一点。


不幸的是,当副本完成时,没有任何形式的通知。至少我没有找到。



我希望苹果会意识到需要通知iTunes同步,因为这似乎是一般的问题。



一个循环检查新文件的修改时间是否改变可能会起作用,但大部分时间都可能。在某些极端情况下,iOS可以暂停在后台进行各种耗时的工作。



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



Geoff


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

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:

  • Monitor with kqueue().
  • At event, start (or reset existing) timeout.
  • When timeout elapses, do work.

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. The kqueue mechanism indeed does work as a means to be notified when an app's Documents directory is modified.

  2. 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.

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.

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.

Geoff

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

08-23 05:56