NSFileManager contentEqualAtPath:andPath: 比较校验和数据

发布于 2024-09-26 20:38:26 字数 664 浏览 4 评论 0原文

NSFileManager 方法 contentsEqualAtPath:andPath: 是否创建动态校验和来比较两个文件,是否打开文件头并比较文件头详细信息,或者是否使用其他方法比较?

我有一个大约 200,000 个文件的列表,用于比较本地文件与远程服务器卷上的文件的位置。本地文件可能在过去的某个时刻从远程服务器卷复制,我将遍历文件列表以比较每个文件,然后将任何较新的文件从远程服务器卷复制到本地计算机(覆盖任何文件)现存的)。无法保证远程服务器文件是由本地用户创建的(而且很可能不是)。

由于文件很小(大小约为 4K),复杂的文件比较操作可能花费几乎与复制操作一样长的时间。

此操作可能(可以想象但不太可能)在用户会话中多次发生,因此我需要确保使用最有效的检查方法。

该操作本身将在单独的线程上运行,因此在操作完成时我不会遇到束缚用户的问题。

我已经开始实施来测试这一点,但有兴趣看看其他人是否有过快速比较数千个文件的经验,以确定哪些文件需要更新(如果存在较新的文件)。如果有的话,您有什么建议或陷阱需要避免吗?

非常感谢任何建议。

更新

再考虑一下,保留一个跟踪任何更改图像的上次更新时间戳的文件并保留一个执行相同操作并仅比较这两个文档的本地文件可能会更有益。随着我的进步,会更新更多。

Does the NSFileManager method contentsEqualAtPath:andPath: create a dynamic checksum to compare two files, does it open the file header and compare file header details or does it use some other method for comparing?

I have a list of 200,000 or so files to compare where the local files are to be compared with the files on a remote server volume. The local files would have been copied from the remote server volume at some point in the past, and I will be walking the list of files to compare each and then copying over any newer files from the remote server volume to the local machine (overwriting any existing). There is no guarantee that the remote server files were created by the local user (and more than likely they would not have been).

As the files are small (approx. 4K in size) a complex file compare operation might take almost as long as a copy operation.

This operation could (conceivably but not likely) happen multiple times in a user session so I need to make sure that I am using the most efficient method for checking.

The operation itself will run on a separate thread so I don't have issues of tying up the user while the operation completes.

I've started the implementation to test this but was interested to see if anyone else has had any experience comparing thousands of files quickly in order to determine which files need updating if a newer one exists. And if you have, do you have any pointers or pitfalls to avoid?

Any advice much appreciated.

Update

Thinking about this some more, it might be more beneficial to keep a file that tracks the last updated timestamp of any changed images and keep a local file that does the same and just compare those two documents... Will update more as I progress.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2024-10-03 20:38:26

在我看来,对于目录,仅比较文件名(和子目录的文件名)。仅当您显式地将文件路径传递给该方法时,它才会比较文件内容。

It looks to me that for directories only filenames (and filenames of subdirectories) are compared. It only compares file content if you explicitly pass file paths to the method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文