0

If I have 2 Paths for files, both share the same FileStore, how can I verify with Java 17 whether they are pointing to the same file on disk (are hard-linked)? For Unix-like systems there seems at least to be a way to verify whether a file has other hardlinks (get Hard Link Count in Java), but on Windows/NTFS I haven't yet found a way to get either information, except of invoking fsutil hardlink list <file-path> and parsing the output. If necessary, a workaround using JNA would also fine for me.

PS: I have already searched Stackoverflow, but only found similar questions for Python or C#.

Thomas S.
  • 5,804
  • 5
  • 37
  • 72

2 Answers2

0

I doubt it can be done within Java alone.

Try to use getCanonicalPath() to at least get around relative and absolute path names. But this hardly gets you around symlinks, or symlinks in parent folders.

For such things in Linux systems there is the readlink command. There is lots to be found here on StackOverflow about it: https://stackoverflow.com/search?q=readlink

For Windows you already mentioned fsutil.

Queeg
  • 7,748
  • 1
  • 16
  • 42
0

Files.isSameFile(path1, path2) checks whether they are hard-linked.

Thomas S.
  • 5,804
  • 5
  • 37
  • 72