Is there a reliable way to check the identity between files not based on their content?

This is not a question about a specific programming language, I know that Crystal has the same_file?, Ruby has the identical?, and other languages have similar apis. But at least on Windows, the implementations I know of are unreliable. I would like to know what the crystal developers think about this. :thinking:

Btw my view is: it’s impossible. I wonder if that’s true?

Have you tried same_file?. If that’s unreliable then I would think its a bug, or at least should be documented what the edge cases are.

Looks like on windows it compares the dwVolumeSerialNumber, nFileIndexHigh, and nFileIndexLow of each file. Based on BY_HANDLE_FILE_INFORMATION (fileapi.h) - Win32 apps | Microsoft Docs, it sounds like that should be fairly robust.

@Blacksmoke16 Just to clarify, what I mean by unreliable doesn’t mean a bug in the API, it’s more of a filesystem driver feature.

AFAIK almost all implementations use GetFileInformationByHandle(Ex) to retrieve file info you mentioned. If the file is on a network filesystem (e.g. CIFS), an arbitrary serial number and file index can be returned by filesystem driver. From a security point of view, it is not very reliable if all the application code knows is only two file paths and makes security decisions based on these APIs.