Browse Source

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
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
5cf39a2970
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 19
      src/base/utils/fs.cpp

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

Loading…
Cancel
Save