Add isNetworkFileSystem() detection on Windows

This allows network mounts to be monitored correctly by polling timer.
This commit is contained in:
Chocobo1 2018-10-12 00:00:48 +08:00
parent fb8fad3fa1
commit cff5af2e76
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
4 changed files with 17 additions and 16 deletions

View file

@ -30,6 +30,10 @@
#include <cstring>
#if defined(Q_OS_WIN)
#include <memory>
#endif
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
@ -301,9 +305,17 @@ bool Utils::Fs::isRegularFile(const QString &path)
return (st.st_mode & S_IFMT) == S_IFREG;
}
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU
#if !defined Q_OS_HAIKU
bool Utils::Fs::isNetworkFileSystem(const QString &path)
{
#if defined(Q_OS_WIN)
const std::wstring pathW {path.toStdWString()};
std::unique_ptr<wchar_t[]> volumePath {new wchar_t[path.length() + 1] {}};
if (!::GetVolumePathNameW(pathW.c_str(), volumePath.get(), (path.length() + 1)))
return false;
return (::GetDriveTypeW(volumePath.get()) == DRIVE_REMOTE);
#else
QString file = path;
if (!file.endsWith('/'))
file += '/';
@ -312,7 +324,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
struct statfs buf {};
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
return false;
#if defined(Q_OS_MAC) || defined(Q_OS_OPENBSD)
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
@ -332,5 +343,6 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path)
return false;
}
#endif
#endif
}
#endif