2015-05-06 14:53:27 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2018-04-14 22:53:45 +03:00
|
|
|
* Copyright (C) 2012 Christophe Dumez <chris@qbittorrent.org>
|
2015-05-06 14:53:27 +03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*/
|
|
|
|
|
2016-05-03 21:45:06 +02:00
|
|
|
#include "fs.h"
|
|
|
|
|
2020-04-12 18:08:19 +03:00
|
|
|
#include <cerrno>
|
2017-10-14 16:27:21 +03:00
|
|
|
#include <cstring>
|
|
|
|
|
2018-10-12 00:00:48 +08:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <memory>
|
|
|
|
#endif
|
|
|
|
|
2018-03-19 15:32:38 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2017-02-07 14:07:59 +08:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <Windows.h>
|
2019-09-05 20:11:33 +08:00
|
|
|
#elif defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD)
|
2015-05-06 14:53:27 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#elif defined(Q_OS_HAIKU)
|
|
|
|
#include <kernel/fs_info.h>
|
|
|
|
#else
|
|
|
|
#include <sys/vfs.h>
|
2017-10-14 16:27:21 +03:00
|
|
|
#include <unistd.h>
|
2015-05-06 14:53:27 +03:00
|
|
|
#endif
|
2017-02-07 14:07:59 +08:00
|
|
|
|
2019-05-16 13:41:29 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QStorageInfo>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
|
2017-02-07 14:07:59 +08:00
|
|
|
#include "base/bittorrent/torrenthandle.h"
|
2018-02-16 18:31:48 +00:00
|
|
|
#include "base/global.h"
|
2015-05-06 14:53:27 +03:00
|
|
|
|
2017-08-15 16:17:57 +03:00
|
|
|
QString Utils::Fs::toNativePath(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
|
|
|
return QDir::toNativeSeparators(path);
|
|
|
|
}
|
|
|
|
|
2019-06-16 20:14:15 +03:00
|
|
|
QString Utils::Fs::toUniformPath(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
|
|
|
return QDir::fromNativeSeparators(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the file extension part of a file name.
|
|
|
|
*/
|
|
|
|
QString Utils::Fs::fileExtension(const QString &filename)
|
|
|
|
{
|
2019-02-21 23:31:43 +02:00
|
|
|
const QString ext = QString(filename).remove(QB_EXT);
|
2018-07-21 13:28:13 +08:00
|
|
|
const int pointIndex = ext.lastIndexOf('.');
|
2017-08-15 16:17:57 +03:00
|
|
|
return (pointIndex >= 0) ? ext.mid(pointIndex + 1) : QString();
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 16:17:57 +03:00
|
|
|
QString Utils::Fs::fileName(const QString &filePath)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2019-06-16 20:14:15 +03:00
|
|
|
const QString path = toUniformPath(filePath);
|
2018-07-21 13:28:13 +08:00
|
|
|
const int slashIndex = path.lastIndexOf('/');
|
2017-08-15 16:17:57 +03:00
|
|
|
if (slashIndex == -1)
|
2015-05-06 14:53:27 +03:00
|
|
|
return path;
|
2017-08-15 16:17:57 +03:00
|
|
|
return path.mid(slashIndex + 1);
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 16:17:57 +03:00
|
|
|
QString Utils::Fs::folderName(const QString &filePath)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2019-06-16 20:14:15 +03:00
|
|
|
const QString path = toUniformPath(filePath);
|
2018-07-21 13:28:13 +08:00
|
|
|
const int slashIndex = path.lastIndexOf('/');
|
2017-08-15 16:17:57 +03:00
|
|
|
if (slashIndex == -1)
|
2015-05-06 14:53:27 +03:00
|
|
|
return path;
|
2017-08-15 16:17:57 +03:00
|
|
|
return path.left(slashIndex);
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-14 01:36:21 +02:00
|
|
|
* This function will first check if there are only system cache files, e.g. `Thumbs.db`,
|
|
|
|
* `.DS_Store` and/or only temp files that end with '~', e.g. `filename~`.
|
|
|
|
* If they are the only files it will try to remove them and delete the folder.
|
|
|
|
* This action will be performed for each subfolder starting from the deepest folder.
|
|
|
|
* There is an inherent race condition here. A file might appear after it is checked
|
|
|
|
* that only the above mentioned "useless" files exist but before the whole folder is removed.
|
|
|
|
* In this case, the folder will not be removed but the "useless" files will be deleted.
|
2015-05-06 14:53:27 +03:00
|
|
|
*/
|
2017-08-15 16:17:57 +03:00
|
|
|
bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2017-04-26 13:15:37 +03:00
|
|
|
if (path.isEmpty() || !QDir(path).exists())
|
2017-08-15 16:17:57 +03:00
|
|
|
return true;
|
2015-05-06 14:53:27 +03:00
|
|
|
|
2018-07-23 12:49:32 +08:00
|
|
|
const QStringList deleteFilesList = {
|
2015-08-09 15:27:56 +08:00
|
|
|
// Windows
|
2019-12-14 01:36:21 +02:00
|
|
|
QLatin1String("Thumbs.db"),
|
|
|
|
QLatin1String("desktop.ini"),
|
2015-08-09 15:27:56 +08:00
|
|
|
// Linux
|
2019-12-14 01:36:21 +02:00
|
|
|
QLatin1String(".directory"),
|
2015-08-09 15:27:56 +08:00
|
|
|
// Mac OS
|
2019-12-14 01:36:21 +02:00
|
|
|
QLatin1String(".DS_Store")
|
2015-08-09 15:27:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// travel from the deepest folder and remove anything unwanted on the way out.
|
2018-07-21 13:28:13 +08:00
|
|
|
QStringList dirList(path + '/'); // get all sub directories paths
|
2015-08-09 15:27:56 +08:00
|
|
|
QDirIterator iter(path, (QDir::AllDirs | QDir::NoDotAndDotDot), QDirIterator::Subdirectories);
|
|
|
|
while (iter.hasNext())
|
2018-07-21 13:28:13 +08:00
|
|
|
dirList << iter.next() + '/';
|
2017-08-15 16:17:57 +03:00
|
|
|
// sort descending by directory depth
|
|
|
|
std::sort(dirList.begin(), dirList.end()
|
2018-07-21 13:28:13 +08:00
|
|
|
, [](const QString &l, const QString &r) { return l.count('/') > r.count('/'); });
|
2015-08-09 15:27:56 +08:00
|
|
|
|
2018-11-27 22:15:04 +02:00
|
|
|
for (const QString &p : asConst(dirList)) {
|
2019-02-21 23:31:43 +02:00
|
|
|
const QDir dir(p);
|
2019-12-14 01:36:21 +02:00
|
|
|
// A deeper folder may have not been removed in the previous iteration
|
|
|
|
// so don't remove anything from this folder either.
|
|
|
|
if (!dir.isEmpty(QDir::Dirs | QDir::NoDotAndDotDot))
|
|
|
|
continue;
|
|
|
|
|
2018-11-18 20:40:37 +02:00
|
|
|
const QStringList tmpFileList = dir.entryList(QDir::Files);
|
2019-12-14 01:36:21 +02:00
|
|
|
|
|
|
|
// deleteFilesList contains unwanted files, usually created by the OS
|
|
|
|
// temp files on linux usually end with '~', e.g. `filename~`
|
|
|
|
const bool hasOtherFiles = std::any_of(tmpFileList.cbegin(), tmpFileList.cend(), [&deleteFilesList](const QString &f)
|
|
|
|
{
|
|
|
|
return (!f.endsWith('~') && !deleteFilesList.contains(f, Qt::CaseInsensitive));
|
|
|
|
});
|
|
|
|
if (hasOtherFiles)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const QString &f : tmpFileList)
|
|
|
|
forceRemove(p + f);
|
2015-08-09 15:27:56 +08:00
|
|
|
|
|
|
|
// remove directory if empty
|
|
|
|
dir.rmdir(p);
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
2015-08-09 15:27:56 +08:00
|
|
|
|
|
|
|
return QDir(path).exists();
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-14 22:53:45 +03:00
|
|
|
* Removes the file with the given filePath.
|
2015-05-06 14:53:27 +03:00
|
|
|
*
|
|
|
|
* This function will try to fix the file permissions before removing it.
|
|
|
|
*/
|
2017-08-15 16:17:57 +03:00
|
|
|
bool Utils::Fs::forceRemove(const QString &filePath)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2017-08-15 16:17:57 +03:00
|
|
|
QFile f(filePath);
|
2015-05-06 14:53:27 +03:00
|
|
|
if (!f.exists())
|
|
|
|
return true;
|
|
|
|
// Make sure we have read/write permissions
|
|
|
|
f.setPermissions(f.permissions() | QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser);
|
|
|
|
// Remove the file
|
|
|
|
return f.remove();
|
|
|
|
}
|
|
|
|
|
2015-06-11 20:43:41 +03:00
|
|
|
/**
|
|
|
|
* Removes directory and its content recursively.
|
|
|
|
*/
|
2017-04-26 13:15:37 +03:00
|
|
|
void Utils::Fs::removeDirRecursive(const QString &path)
|
2015-06-17 19:18:35 +03:00
|
|
|
{
|
2017-04-26 13:15:37 +03:00
|
|
|
if (!path.isEmpty())
|
|
|
|
QDir(path).removeRecursively();
|
2015-06-11 20:43:41 +03:00
|
|
|
}
|
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
/**
|
|
|
|
* Returns the size of a file.
|
|
|
|
* If the file is a folder, it will compute its size based on its content.
|
|
|
|
*
|
|
|
|
* Returns -1 in case of error.
|
|
|
|
*/
|
2017-08-15 16:17:57 +03:00
|
|
|
qint64 Utils::Fs::computePathSize(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
|
|
|
// Check if it is a file
|
2019-02-21 23:31:43 +02:00
|
|
|
const QFileInfo fi(path);
|
2015-05-06 14:53:27 +03:00
|
|
|
if (!fi.exists()) return -1;
|
|
|
|
if (fi.isFile()) return fi.size();
|
2016-04-28 19:04:51 +08:00
|
|
|
|
2015-05-06 14:53:27 +03:00
|
|
|
// Compute folder size based on its content
|
|
|
|
qint64 size = 0;
|
2016-04-28 19:04:51 +08:00
|
|
|
QDirIterator iter(path, QDir::Files | QDir::Hidden | QDir::NoSymLinks, QDirIterator::Subdirectories);
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
iter.next();
|
|
|
|
size += iter.fileInfo().size();
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes deep comparison of two files to make sure they are identical.
|
|
|
|
*/
|
2017-08-15 16:17:57 +03:00
|
|
|
bool Utils::Fs::sameFiles(const QString &path1, const QString &path2)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
|
|
|
QFile f1(path1), f2(path2);
|
|
|
|
if (!f1.exists() || !f2.exists()) return false;
|
|
|
|
if (f1.size() != f2.size()) return false;
|
|
|
|
if (!f1.open(QIODevice::ReadOnly)) return false;
|
2016-04-28 19:04:51 +08:00
|
|
|
if (!f2.open(QIODevice::ReadOnly)) return false;
|
|
|
|
|
|
|
|
const int readSize = 1024 * 1024; // 1 MiB
|
2018-06-14 14:46:50 +03:00
|
|
|
while (!f1.atEnd() && !f2.atEnd()) {
|
2016-04-28 19:04:51 +08:00
|
|
|
if (f1.read(readSize) != f2.read(readSize))
|
|
|
|
return false;
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
2016-04-28 19:04:51 +08:00
|
|
|
return true;
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 23:31:43 +02:00
|
|
|
QString Utils::Fs::toValidFileSystemName(const QString &name, const bool allowSeparators, const QString &pad)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2018-05-24 23:41:03 +08:00
|
|
|
const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+");
|
2015-12-01 17:41:56 +03:00
|
|
|
|
2016-02-09 11:56:48 +03:00
|
|
|
QString validName = name.trimmed();
|
2017-03-07 16:10:42 +03:00
|
|
|
validName.replace(regex, pad);
|
2016-02-09 11:56:48 +03:00
|
|
|
qDebug() << "toValidFileSystemName:" << name << "=>" << validName;
|
2015-12-01 17:41:56 +03:00
|
|
|
|
|
|
|
return validName;
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 23:31:43 +02:00
|
|
|
bool Utils::Fs::isValidFileSystemName(const QString &name, const bool allowSeparators)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2016-02-09 11:56:48 +03:00
|
|
|
if (name.isEmpty()) return false;
|
|
|
|
|
2019-09-05 02:00:10 +08:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
const QRegularExpression regex {allowSeparators
|
|
|
|
? QLatin1String("[:?\"*<>|]")
|
|
|
|
: QLatin1String("[\\\\/:?\"*<>|]")};
|
|
|
|
#elif defined(Q_OS_MACOS)
|
|
|
|
const QRegularExpression regex {allowSeparators
|
|
|
|
? QLatin1String("[\\0:]")
|
|
|
|
: QLatin1String("[\\0/:]")};
|
|
|
|
#else
|
|
|
|
const QRegularExpression regex {allowSeparators
|
|
|
|
? QLatin1String("[\\0]")
|
|
|
|
: QLatin1String("[\\0/]")};
|
|
|
|
#endif
|
2016-02-09 11:56:48 +03:00
|
|
|
return !name.contains(regex);
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2017-05-14 23:57:24 +02:00
|
|
|
qint64 Utils::Fs::freeDiskSpaceOnPath(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2017-05-14 23:57:24 +02:00
|
|
|
if (path.isEmpty()) return -1;
|
2016-12-08 01:14:55 +08:00
|
|
|
|
2017-05-14 23:57:24 +02:00
|
|
|
return QStorageInfo(path).bytesAvailable();
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 16:17:57 +03:00
|
|
|
QString Utils::Fs::branchPath(const QString &filePath, QString *removed)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2019-06-16 20:14:15 +03:00
|
|
|
QString ret = toUniformPath(filePath);
|
2018-07-21 13:28:13 +08:00
|
|
|
if (ret.endsWith('/'))
|
2015-05-06 14:53:27 +03:00
|
|
|
ret.chop(1);
|
2018-07-21 13:28:13 +08:00
|
|
|
const int slashIndex = ret.lastIndexOf('/');
|
2015-05-06 14:53:27 +03:00
|
|
|
if (slashIndex >= 0) {
|
|
|
|
if (removed)
|
|
|
|
*removed = ret.mid(slashIndex + 1);
|
|
|
|
ret = ret.left(slashIndex);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Utils::Fs::sameFileNames(const QString &first, const QString &second)
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
|
|
|
return QString::compare(first, second, Qt::CaseSensitive) == 0;
|
|
|
|
#else
|
|
|
|
return QString::compare(first, second, Qt::CaseInsensitive) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Utils::Fs::expandPath(const QString &path)
|
|
|
|
{
|
2019-02-21 23:31:43 +02:00
|
|
|
const QString ret = path.trimmed();
|
2015-05-06 14:53:27 +03:00
|
|
|
if (ret.isEmpty())
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return QDir::cleanPath(ret);
|
|
|
|
}
|
|
|
|
|
2017-08-15 16:17:57 +03:00
|
|
|
QString Utils::Fs::expandPathAbs(const QString &path)
|
2015-05-06 14:53:27 +03:00
|
|
|
{
|
2017-08-15 16:17:57 +03:00
|
|
|
return QDir(expandPath(path)).absolutePath();
|
2015-05-06 14:53:27 +03:00
|
|
|
}
|
|
|
|
|
2016-11-29 17:55:58 +08:00
|
|
|
QString Utils::Fs::tempPath()
|
|
|
|
{
|
|
|
|
static const QString path = QDir::tempPath() + "/.qBittorrent/";
|
|
|
|
QDir().mkdir(path);
|
|
|
|
return path;
|
|
|
|
}
|
2017-10-14 16:27:21 +03:00
|
|
|
|
|
|
|
bool Utils::Fs::isRegularFile(const QString &path)
|
|
|
|
{
|
|
|
|
struct ::stat st;
|
|
|
|
if (::stat(path.toUtf8().constData(), &st) != 0) {
|
|
|
|
// analyse erno and log the error
|
|
|
|
const auto err = errno;
|
|
|
|
qDebug("Could not get file stats for path '%s'. Error: %s"
|
|
|
|
, qUtf8Printable(path), qUtf8Printable(strerror(err)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (st.st_mode & S_IFMT) == S_IFREG;
|
|
|
|
}
|
2018-03-19 15:32:38 +08:00
|
|
|
|
2018-10-12 00:00:48 +08:00
|
|
|
#if !defined Q_OS_HAIKU
|
2018-03-19 15:32:38 +08:00
|
|
|
bool Utils::Fs::isNetworkFileSystem(const QString &path)
|
|
|
|
{
|
2018-10-12 00:00:48 +08:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
const std::wstring pathW {path.toStdWString()};
|
2020-03-05 00:39:41 +08:00
|
|
|
auto volumePath = std::make_unique<wchar_t[]>(path.length() + 1);
|
2018-10-12 00:00:48 +08:00
|
|
|
if (!::GetVolumePathNameW(pathW.c_str(), volumePath.get(), (path.length() + 1)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (::GetDriveTypeW(volumePath.get()) == DRIVE_REMOTE);
|
2019-09-05 20:11:33 +08:00
|
|
|
#elif defined(Q_OS_MACOS) || defined(Q_OS_OPENBSD)
|
2018-03-19 15:32:38 +08:00
|
|
|
QString file = path;
|
|
|
|
if (!file.endsWith('/'))
|
|
|
|
file += '/';
|
|
|
|
file += '.';
|
|
|
|
|
|
|
|
struct statfs buf {};
|
|
|
|
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
|
|
|
|
return false;
|
2018-10-12 00:00:57 +08:00
|
|
|
|
2018-03-19 15:32:38 +08:00
|
|
|
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
|
2018-10-10 09:52:35 +08:00
|
|
|
return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|
|
|
|
|| (strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0)
|
2018-03-19 15:32:38 +08:00
|
|
|
|| (strncmp(buf.f_fstypename, "smbfs", sizeof(buf.f_fstypename)) == 0));
|
2018-11-06 17:49:17 +02:00
|
|
|
#else // Q_OS_WIN
|
2018-10-12 00:00:57 +08:00
|
|
|
QString file = path;
|
|
|
|
if (!file.endsWith('/'))
|
|
|
|
file += '/';
|
|
|
|
file += '.';
|
|
|
|
|
|
|
|
struct statfs buf {};
|
|
|
|
if (statfs(file.toLocal8Bit().constData(), &buf) != 0)
|
|
|
|
return false;
|
|
|
|
|
2018-10-10 09:52:35 +08:00
|
|
|
// Magic number references:
|
|
|
|
// 1. /usr/include/linux/magic.h
|
|
|
|
// 2. https://github.com/coreutils/coreutils/blob/master/src/stat.c
|
2019-10-31 12:59:54 +08:00
|
|
|
switch (static_cast<unsigned int>(buf.f_type)) {
|
2018-10-10 09:52:35 +08:00
|
|
|
case 0xFF534D42: // CIFS_MAGIC_NUMBER
|
|
|
|
case 0x6969: // NFS_SUPER_MAGIC
|
|
|
|
case 0x517B: // SMB_SUPER_MAGIC
|
|
|
|
case 0xFE534D42: // S_MAGIC_SMB2
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-06 17:49:17 +02:00
|
|
|
#endif // Q_OS_WIN
|
2018-03-19 15:32:38 +08:00
|
|
|
}
|
2018-11-06 17:49:17 +02:00
|
|
|
#endif // Q_OS_HAIKU
|