Skip to content

Commit

Permalink
core: fix on_torrent_added() probelms introduced by upstream PR bdutro#7
Browse files Browse the repository at this point in the history


- in else-block, label_id param, referenced later on, was left undefined;
  • Loading branch information
laur89 committed Dec 6, 2021
1 parent 192c4f1 commit 9ce3fdd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions labelplus/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,23 @@ def on_torrent_added(self, torrent_id, from_state):
label_id = self.__pending_labels.pop(torrent_id)
self._set_torrent_label(torrent_id, label_id)
else:
target_label_id = self._find_autolabel_match(torrent_id)
if target_label_id != labelplus.common.label.ID_NONE:
self._do_autolabel_torrent(torrent_id)
label_id = self._find_autolabel_match(torrent_id)
if label_id != labelplus.common.label.ID_NONE:
# note we only invoke _do_autolabel_torrent() here if id != ID_NONE, as
# otherwise already-set label (via pending_labels) would get reset
# even if no autolabels apply (see upstream PR #7)
label_id = self._do_autolabel_torrent(torrent_id)

# TODO: alternative else block:
# the above version will always replace label set via pending_labels if
# an autolabel rule applies.
# this version on the other hand invokes _do_autolabel_torrent() _only_
# if torrent doesn't already have an ID set; to make sure this is only
# executed for magents, we could also add additional [torrent_id in self.__pending_magnet_ids] check to the mix:
# label_id = self._get_torrent_label_id(torrent_id)
# if label_id == labelplus.common.label.ID_NONE:
# OR, as described above: if label_id == labelplus.common.label.ID_NONE and torrent_id in self.__pending_magnet_ids:
# label_id = self._do_autolabel_torrent(torrent_id)

if label_id != labelplus.common.label.ID_NONE:
self._move_torrents([torrent_id])
Expand All @@ -749,6 +763,11 @@ def on_torrent_metadata_received(self, alert):
torrent_id = str(alert.handle.info_hash())
except RuntimeError:
return

# TODO: mhertz' version had following assert commented out; think
# he might be right, it looks like self._torrents is only initialized at startup,
# but later-added torrents are not added to the list? or maybe self._torrents is
# a live view??
assert(torrent_id in self._torrents)
if torrent_id in self.__pending_magnet_ids:
self.on_torrent_added(torrent_id, False)
Expand Down

0 comments on commit 9ce3fdd

Please sign in to comment.