diff --git a/src/base/path.cpp b/src/base/path.cpp index dee1c50c4..66270154c 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -218,6 +218,15 @@ QString Path::toString() const 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) { *this = *this / other; diff --git a/src/base/path.h b/src/base/path.h index 6fbb94604..1b9e95198 100644 --- a/src/base/path.h +++ b/src/base/path.h @@ -29,6 +29,8 @@ #pragma once +#include + #include #include #include @@ -69,6 +71,7 @@ public: QString data() const; QString toString() const override; + std::filesystem::path toStdFsPath() const; Path &operator/=(const Path &other); Path &operator+=(QStringView str); diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 044b7d54d..ac99e40fe 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -31,6 +31,7 @@ #include #include +#include #if defined(Q_OS_WIN) #include @@ -57,8 +58,8 @@ #include #include #include -#include #include +#include #include "base/global.h" #include "base/path.h" @@ -214,17 +215,8 @@ Path Utils::Fs::tempPath() bool Utils::Fs::isRegularFile(const Path &path) { - struct ::stat st; - if (::stat(path.toString().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.toString()), strerror(err)); - return false; - } - - return (st.st_mode & S_IFMT) == S_IFREG; + std::error_code ec; + return std::filesystem::is_regular_file(path.toStdFsPath(), ec); } bool Utils::Fs::isNetworkFileSystem(const Path &path)