mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Merge pull request #15530 from Chocobo1/errmsg
Log error message in DownloadHandlerImpl class
This commit is contained in:
commit
3301797491
@ -38,34 +38,30 @@
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct Sample
|
struct Sample
|
||||||
{
|
{
|
||||||
Sample()
|
constexpr Sample() = default;
|
||||||
: download()
|
|
||||||
, upload()
|
constexpr Sample(const T dl, const T ul)
|
||||||
|
: download {dl}
|
||||||
|
, upload {ul}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Sample(T dl, T ul)
|
constexpr Sample<T> &operator+=(const Sample<T> &other)
|
||||||
: download(dl)
|
|
||||||
, upload(ul)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Sample<T> &operator+=(const Sample<T> &other)
|
|
||||||
{
|
{
|
||||||
download += other.download;
|
download += other.download;
|
||||||
upload += other.upload;
|
upload += other.upload;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sample<T> &operator-=(const Sample<T> &other)
|
constexpr Sample<T> &operator-=(const Sample<T> &other)
|
||||||
{
|
{
|
||||||
download -= other.download;
|
download -= other.download;
|
||||||
upload -= other.upload;
|
upload -= other.upload;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T download;
|
T download {};
|
||||||
T upload;
|
T upload {};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Sample<qlonglong> SpeedSample;
|
typedef Sample<qlonglong> SpeedSample;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "base/3rdparty/expected.hpp"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/gzip.h"
|
#include "base/utils/gzip.h"
|
||||||
#include "base/utils/io.h"
|
#include "base/utils/io.h"
|
||||||
@ -41,18 +42,14 @@ const int MAX_REDIRECTIONS = 20; // the common value for web browsers
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
nonstd::expected<QString, QString> saveToTempFile(const QByteArray &data)
|
||||||
{
|
{
|
||||||
if (!filePath.isEmpty())
|
|
||||||
return Utils::IO::saveToFile(filePath, replyData).has_value();
|
|
||||||
|
|
||||||
QTemporaryFile file {Utils::Fs::tempPath()};
|
QTemporaryFile file {Utils::Fs::tempPath()};
|
||||||
if (!file.open() || (file.write(replyData) != replyData.length()) || !file.flush())
|
if (!file.open() || (file.write(data) != data.length()) || !file.flush())
|
||||||
return false;
|
return nonstd::make_unexpected(file.errorString());
|
||||||
|
|
||||||
file.setAutoRemove(false);
|
file.setAutoRemove(false);
|
||||||
filePath = file.fileName();
|
return file.fileName();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,11 +127,23 @@ void DownloadHandlerImpl::processFinishedDownload()
|
|||||||
|
|
||||||
if (m_downloadRequest.saveToFile())
|
if (m_downloadRequest.saveToFile())
|
||||||
{
|
{
|
||||||
QString filePath {m_downloadRequest.destFileName()};
|
const QString destinationPath = m_downloadRequest.destFileName();
|
||||||
if (saveToFile(m_result.data, filePath))
|
if (destinationPath.isEmpty())
|
||||||
m_result.filePath = filePath;
|
{
|
||||||
|
const nonstd::expected<QString, QString> result = saveToTempFile(m_result.data);
|
||||||
|
if (result)
|
||||||
|
m_result.filePath = result.value();
|
||||||
|
else
|
||||||
|
setError(tr("I/O Error: %1").arg(result.error()));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
setError(tr("I/O Error"));
|
{
|
||||||
|
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(destinationPath, m_result.data);
|
||||||
|
if (result)
|
||||||
|
m_result.filePath = destinationPath;
|
||||||
|
else
|
||||||
|
setError(tr("I/O Error: %1").arg(result.error()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
|
@ -33,13 +33,12 @@
|
|||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#ifndef NOMINMAX
|
|
||||||
#define NOMINMAX
|
|
||||||
#endif
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Ntsecapi.h>
|
#include <Ntsecapi.h>
|
||||||
#else // Q_OS_WIN
|
#else // Q_OS_WIN
|
||||||
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -97,7 +96,7 @@ namespace
|
|||||||
: m_randDev {fopen("/dev/urandom", "rb")}
|
: m_randDev {fopen("/dev/urandom", "rb")}
|
||||||
{
|
{
|
||||||
if (!m_randDev)
|
if (!m_randDev)
|
||||||
qFatal("Failed to open /dev/urandom");
|
qFatal("Failed to open /dev/urandom. Reason: %s. Error code: %d.\n", std::strerror(errno), errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RandomLayer()
|
~RandomLayer()
|
||||||
@ -119,7 +118,7 @@ namespace
|
|||||||
{
|
{
|
||||||
result_type buf = 0;
|
result_type buf = 0;
|
||||||
if (fread(&buf, sizeof(buf), 1, m_randDev) != 1)
|
if (fread(&buf, sizeof(buf), 1, m_randDev) != 1)
|
||||||
qFatal("Read /dev/urandom error");
|
qFatal("Read /dev/urandom error. Reason: %s. Error code: %d.\n", std::strerror(errno), errno);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user