1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-12 07:48:04 +00:00

Reuse code path

`buf.f_type` should be compatible across platforms.
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/statfs.2.html
This commit is contained in:
Chocobo1 2021-09-27 22:07:29 +08:00
parent 1c9321d5a1
commit 5cf39a2970
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -341,29 +341,27 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
if (!::GetVolumePathNameW(pathW.c_str(), volumePath.get(), (path.length() + 1)))
return false;
return (::GetDriveTypeW(volumePath.get()) == DRIVE_REMOTE);
#elif defined(Q_OS_MACOS) || defined(Q_OS_OPENBSD)
QString file = path;
if (!file.endsWith('/'))
file += '/';
file += '.';
struct statfs buf {};
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
return false;
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|| (strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0)
|| (strncmp(buf.f_fstypename, "smbfs", sizeof(buf.f_fstypename)) == 0));
#else
QString file = path;
if (!file.endsWith('/'))
file += '/';
file += '.';
#if defined(Q_OS_MACOS)
struct statfs64 buf {};
if (statfs64(file.toLocal8Bit().constData(), &buf) != 0)
return false;
#else
struct statfs buf {};
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
return false;
#endif
#if defined(Q_OS_OPENBSD)
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|| (strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0)
|| (strncmp(buf.f_fstypename, "smbfs", sizeof(buf.f_fstypename)) == 0));
#else
// Magic number reference:
// https://github.com/coreutils/coreutils/blob/master/src/stat.c
switch (static_cast<quint32>(buf.f_type))
@ -403,5 +401,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
return false;
#endif
#endif
}
#endif // Q_OS_HAIKU