mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 20:44:15 +00:00
Simplify implementation
This also enable each platform to provide its own optimal implementation of it.
This commit is contained in:
parent
5b269a782a
commit
727d20cc92
@ -218,6 +218,15 @@ QString Path::toString() const
|
|||||||
return QDir::toNativeSeparators(m_pathStr);
|
return QDir::toNativeSeparators(m_pathStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::filesystem::path Path::toStdFsPath() const
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
return {data().toStdWString(), std::filesystem::path::format::generic_format};
|
||||||
|
#else
|
||||||
|
return {data().toStdString(), std::filesystem::path::format::generic_format};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
Path &Path::operator/=(const Path &other)
|
Path &Path::operator/=(const Path &other)
|
||||||
{
|
{
|
||||||
*this = *this / other;
|
*this = *this / other;
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -69,6 +71,7 @@ public:
|
|||||||
|
|
||||||
QString data() const;
|
QString data() const;
|
||||||
QString toString() const override;
|
QString toString() const override;
|
||||||
|
std::filesystem::path toStdFsPath() const;
|
||||||
|
|
||||||
Path &operator/=(const Path &other);
|
Path &operator/=(const Path &other);
|
||||||
Path &operator+=(QStringView str);
|
Path &operator+=(QStringView str);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -57,8 +58,8 @@
|
|||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QStorageInfo>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QStorageInfo>
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
@ -214,17 +215,8 @@ Path Utils::Fs::tempPath()
|
|||||||
|
|
||||||
bool Utils::Fs::isRegularFile(const Path &path)
|
bool Utils::Fs::isRegularFile(const Path &path)
|
||||||
{
|
{
|
||||||
struct ::stat st;
|
std::error_code ec;
|
||||||
if (::stat(path.toString().toUtf8().constData(), &st) != 0)
|
return std::filesystem::is_regular_file(path.toStdFsPath(), ec);
|
||||||
{
|
|
||||||
// analyse erno and log the error
|
|
||||||
const auto err = errno;
|
|
||||||
qDebug("Could not get file stats for path '%s'. Error: %s"
|
|
||||||
, qUtf8Printable(path.toString()), strerror(err));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (st.st_mode & S_IFMT) == S_IFREG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::Fs::isNetworkFileSystem(const Path &path)
|
bool Utils::Fs::isNetworkFileSystem(const Path &path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user