有没有办法识别文件已被修改和移动?

发布于 2024-08-31 11:25:10 字数 416 浏览 1 评论 0原文

我正在编写一个应用程序,用于对文件进行编目,并通过单独的“side-car”文件为它们添加额外的元数据。如果通过我的程序对文件进行更改,那么它能够使它们及其相应的元数据文件之间的所有内容保持同步。但是,我正在尝试找出一种方法来处理有人在我的程序未运行时手动修改文件的情况。

当我的程序启动时,它会扫描文件系统,并将找到的文件与它记得的文件的先前记录进行比较。删除或添加文件后更新相当简单。但是,如果文件被移动或重命名,那么我的程序会将其视为旧文件被删除并添加新文件。但我不想失去文件与其元数据之间的关联。

我想我可以存储每个文件的哈希值,这样我就可以检查新发现的文件是否确实是先前已知的已移动或重命名的文件。但是,如果文件同时被移动/重命名和修改,则哈希值也将不匹配。

那么,是否有其他一些我可以跟踪的文件唯一标识符,即使在重命名、移动或修改后,该标识符仍保留在文件中?

I'm writing an application that catalogs files, and attributes them with extra meta data through separate "side-car" files. If changes to the files are made through my program then it is able to keep everything in sync between them and their corresponding meta data files. However, I'm trying to figure out a way to deal with someone modifying the files manually while my program is not running.

When my program starts up it scans the file system and compares the files it finds to it's previous record of what files it remembers being there. It's fairly straight forward to update after a file has been deleted or added. However, if a file was moved or renamed then my program sees that as the old file being deleted, and the new file being added. Yet I don't want to loose the association between the file and its metadata.

I was thinking I could store a hash from each file so I could check to see if newly found files were really previously known files that had been moved or renamed. However, if the file is both moved/renamed and modified then the hash would not match either.

So is there some other unique identifier of a file that I can track which stays with it even after it is renamed, moved, or modified?

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

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

发布评论

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

评论(1

把人绕傻吧 2024-09-07 11:25:10

该文件没有唯一标识符。您可以使用的最好方法是启发式和差异比较方法。如果删除的文件和添加的文件之间的差异很小,那么这可能是修改+移动操作。或者也许不是。

git 有一个非常好的文件重命名/移动检测器。也许你可以从中借鉴一些想法。

There is no unique identifier for the file. The best you can use is a heuristic and difference comparison method. If the difference is small between a removed and the added file, then perhaps this was a modify + move operation. Or maybe not.

git has a pretty good file renaming/moving detector. Perhaps you can borrow some ideas from it.

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