admin 管理员组文章数量: 1086019
I'm trying to find a reliable way to detect whether a file has changed, so I can avoid recomputing its SHA-256 hash. I'm manually caching the hash codes for performance reasons, and I want to safely reuse them when files haven't changed.
Here’s my setup and current thinking:
Based on my research, the most reliable way to determine if two files are identical is by comparing their SHA-256 hashes.
I'm scanning all files in a source directory and comparing them to files in a target directory, based on their content.
To improve performance, I want to cache the SHA-256 hashes of files in the source directory and skip re-hashing files that haven't changed on future scans.
However, I understand that checking only the last modified time (even combined with name or size) may not be reliable — file content can be changed without modifying mtime (e.g., if spoofed manually or using OS-level tricks).
My question is:
Is there any way to detect whether a file’s contents have changed — faster than recomputing its hash — so I can safely decide whether to trust a previously cached SHA-256 hash?
I'm looking for cross-platform solutions (Windows, macOS, and Linux), but OS-specific techniques are welcome too.
Thanks in advance!
本文标签:
版权声明:本文标题:performance - How can I reliably detect if a file has changed (without re-hashing), in order to safely cache its SHA-256 hash? - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743992797a2515042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论