From 5cf39a297004a1330af4a039fba99d0c286d48e9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 Sep 2021 22:07:29 +0800 Subject: [PATCH] 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 --- src/base/utils/fs.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 5f3597483..04ec4e4b8 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -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) +#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 - QString file = path; - if (!file.endsWith('/')) - file += '/'; - file += '.'; - - struct statfs buf {}; - if (statfs(file.toLocal8Bit().constData(), &buf) != 0) - return false; - // Magic number reference: // https://github.com/coreutils/coreutils/blob/master/src/stat.c switch (static_cast(buf.f_type)) @@ -403,5 +401,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path) return false; #endif +#endif } #endif // Q_OS_HAIKU