Implement DirAccess.is_equivalent method.

This commit is contained in:
Pāvels Nadtočajevs 2025-03-25 12:47:51 +02:00
parent 6b5b84c0c5
commit d5cea9bb2e
No known key found for this signature in database
GPG key ID: 8413210218EF35D2
7 changed files with 67 additions and 0 deletions

View file

@ -43,6 +43,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#ifdef HAVE_MNTENT
@ -544,6 +545,24 @@ bool DirAccessUnix::is_case_sensitive(const String &p_path) const {
return true;
}
bool DirAccessUnix::is_equivalent(const String &p_path_a, const String &p_path_b) const {
String f1 = fix_path(p_path_a);
struct stat st1 = {};
int err = stat(f1.utf8().get_data(), &st1);
if (err) {
return DirAccess::is_equivalent(p_path_a, p_path_b);
}
String f2 = fix_path(p_path_b);
struct stat st2 = {};
err = stat(f2.utf8().get_data(), &st2);
if (err) {
return DirAccess::is_equivalent(p_path_a, p_path_b);
}
return (st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino);
}
DirAccessUnix::DirAccessUnix() {
dir_stream = nullptr;
_cisdir = false;