Skip to content

Commit

Permalink
Add workaround to show torrent's error when all its trackers have err…
Browse files Browse the repository at this point in the history
…ors (#462)
  • Loading branch information
equeim committed Aug 29, 2024
1 parent 96d5d0c commit fb9e273
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
- Minimum cxxopts version is 3.1.1
- Minimum gettext version is 0.21
- Removed dependency on Qt Concurrent module
- Notification portal is used for notification in Flatpak
- Breeze is used as a fallback icon theme and should be installed as a runtime dependency
- Clarified runtime dependency on Qt's SVG image format plugin
- Notification portal is used for notification in Flatpak
- Added workaround for Transmission not showing an error for torrent when all trackers have failed
- Networking and some other async code is rewritten using C++ coroutines. Hopefully nothing is broken :)

### Fixed
Expand Down
20 changes: 20 additions & 0 deletions src/rpc/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ namespace tremotesf {
updateProperty(*key, i.value(), changed, firstTime, rpc);
}
}
applyTrackerErrorWorkaround(changed);
return changed;
}

Expand All @@ -264,6 +265,7 @@ namespace tremotesf {
updateProperty(*key, values[static_cast<QJsonArray::size_type>(i)], changed, firstTime, rpc);
}
}
applyTrackerErrorWorkaround(changed);
return changed;
}

Expand Down Expand Up @@ -450,6 +452,24 @@ namespace tremotesf {
throw std::logic_error(fmt::format("Can't update key {}", static_cast<int>(intKey)));
}

void TorrentData::applyTrackerErrorWorkaround(bool& changed) {
// Sometimes Transmission doesn't propagate tracker error to the torrent's status
if (error != Error::None) {
return;
}
if (trackers.empty()) {
return;
}
// Only set error if *all* trackers have an error
if (std::ranges::any_of(trackers, [](const Tracker& tracker) { return tracker.errorMessage().isEmpty(); })) {
return;
}
// Set error from first tracker
error = Error::TrackerError;
errorString = trackers.front().errorMessage();
changed = true;
}

Torrent::Torrent(int id, const QJsonObject& object, Rpc* rpc, QObject* parent) : QObject(parent), mRpc(rpc) {
mData.id = id;
[[maybe_unused]] const bool changed = mData.update(object, true, rpc);
Expand Down
1 change: 1 addition & 0 deletions src/rpc/torrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace tremotesf {
void updateProperty(
TorrentData::UpdateKey key, const QJsonValue& value, bool& changed, bool firstTime, const Rpc* rpc
);
void applyTrackerErrorWorkaround(bool& changed);
};

class Torrent final : public QObject {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace tremotesf {
int tier() const { return mTier; }

Status status() const { return mStatus; };
QString errorMessage() const { return mErrorMessage; };
const QString& errorMessage() const { return mErrorMessage; };

int peers() const { return mPeers; };
int seeders() const { return mSeeders; }
Expand Down

0 comments on commit fb9e273

Please sign in to comment.