在 iOS 上,应用程序如何确定另一个进程是否不再写入文件?
我的问题与此非常相似: 使用 kqueue() 监视目录中的更改的最佳方法是什么? 但我对那里的答案不满意。
我有一个 kqueue 设置,当文件复制到我的应用程序的文档目录时会收到通知。当然,复制开始后通知就会触发,但我想知道复制何时完成。当然有比轮询修改时间更好的方法吗?
My question is very similar to this one: What is the optimal way to monitor changes in a directory with a kqueue()? but I'm not satisfied with the answer there.
I have a kqueue setup to be notified when a file is copied to my app's Documents directory. Of course the notification fires as soon as the copying begins, but I want to know when it's completed. Surely there's a better way than polling modification times?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否启动复制并控制文件名?
那么最简单的解决方案可能是复制到临时文件,然后将其重命名为最终名称。这样您就会知道:如果该文件在那里,则不再写入。
Do you initiate the copying and have control over the filenames ?
Then the easiest solution could be to just copy to a temp file and then after that rename it to it's final name.that way you would know: if this file is there-it ist no longer written to.
目前,答案似乎是“否”,因此我采取了轮询相关文件的修改时间的方式。
如果其他人能够提出更好的答案,我会很高兴听到它(并且不会接受这个答案)。
For now, the answer seems to be 'no', so I've resorted to polling the modification time of the file(s) in question.
If someone else is able to come up with a better answer, I'd be glad to hear it (and will un-accept this one).