From 33e090cfcb7dd746ca2a8ac25dc7406516fc93d2 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 20 May 2021 09:30:15 +0300 Subject: [PATCH] Provide correct error description in "upload mode" --- src/base/bittorrent/session.cpp | 3 ++- src/base/bittorrent/torrentimpl.cpp | 16 +++++++++++++++- src/base/bittorrent/torrentimpl.h | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 99439a360..2a0701507 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4736,8 +4736,9 @@ void Session::handleFileErrorAlert(const lt::file_error_alert *p) if (!torrent) return; - const TorrentID id = torrent->id(); + torrent->handleAlert(p); + const TorrentID id = torrent->id(); if (!m_recentErroredTorrents.contains(id)) { m_recentErroredTorrents.insert(id); diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index ea3eec4cd..167e20d73 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -970,7 +970,13 @@ QString TorrentImpl::error() const return QString::fromStdString(m_nativeStatus.errc.message()); if (m_nativeStatus.flags & lt::torrent_flags::upload_mode) - return tr("There's not enough space on disk. Torrent is currently in \"upload only\" mode."); + { + const QString writeErrorStr = tr("Couldn't write to file."); + const QString uploadModeStr = tr("Torrent is currently in \"upload only\" mode."); + const QString errorMessage = QString::fromLocal8Bit(m_lastFileError.error.message().c_str()); + + return writeErrorStr + QLatin1Char(' ') + errorMessage + QLatin1String(". ") + uploadModeStr; + } return {}; } @@ -1887,6 +1893,11 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p) } } +void TorrentImpl::handleFileErrorAlert(const lt::file_error_alert *p) +{ + m_lastFileError = {p->error, p->op}; +} + void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) { Q_UNUSED(p); @@ -1933,6 +1944,9 @@ void TorrentImpl::handleAlert(const lt::alert *a) case lt::file_completed_alert::alert_type: handleFileCompletedAlert(static_cast(a)); break; + case lt::file_error_alert::alert_type: + handleFileErrorAlert(static_cast(a)); + break; case lt::torrent_finished_alert::alert_type: handleTorrentFinishedAlert(static_cast(a)); break; diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index 9aef754dd..25902fa98 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -86,6 +86,12 @@ namespace BitTorrent HandleMetadata }; + struct FileErrorInfo + { + lt::error_code error; + lt::operation_t operation; + }; + class TorrentImpl final : public QObject, public Torrent { Q_DISABLE_COPY(TorrentImpl) @@ -264,6 +270,7 @@ namespace BitTorrent void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p); void handleFileCompletedAlert(const lt::file_completed_alert *p); + void handleFileErrorAlert(const lt::file_error_alert *p); void handleFileRenamedAlert(const lt::file_renamed_alert *p); void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p); void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); @@ -315,6 +322,7 @@ namespace BitTorrent QHash> m_oldPath; QHash m_trackerInfos; + FileErrorInfo m_lastFileError; // Persistent data QString m_name;