Is there a platform agnostic way to check if two files are on the same disk?
Def wanna test this – but the file input method of this class:
oops… I misread your question… sorry…
Or just an MD5?
https://docs.juce.com/master/classMD5.html
question is file are on the same disk… not file are the same on a disk
Match getVolumeLabel of the two files ?
…and there is getVolumeSerialNumber()
I haven’t tested on which OSses it is implemented though, so I guess there will be a follow up question. Otherwise the question was too easy
int File::getVolumeSerialNumber() const
{
return 0;
}
That’s not gonna work.
File::getVolumeLabel()
seems to be implemented on most platforms.
Somehow I had a hunch about that…
I wonder though if the OS guarantees the label to be unique? Otherwise that is also just a hint, not a solution.
This would be solved by adding a getVolumeRoot()
method to the File
class, that for any given path (caveat, it may require the path to be existing), returns the root of the filesystem/volume that contains it.
So for example if you have a disk mounted in “/mnt/usb_drive”,
File ("/mnt/usb_drive/my_dir/my_file.txt").getVolumeRoot(); // returns "/mnt/usb_drive",
while
File ("/etc/some_other_file").getVolumeRoot(); // returns "/".
I’ve found myself in need of something similar in the past, but being unable to implement it in a cross platform way, I abandoned the idea.
With that method available, checking if two files reside on the same filesystem its simply a matter of checking whether the path returned by this getVolumeRoot()
is the same for both