summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2021-02-05 18:55:54 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2021-02-05 20:33:19 +0000
commitda5d5bee209df81d6957aacb153eac00c9a457e6 (patch)
treeb000af9f138ea3dbb185ce0e878754e79597ddfa
parent6d9dc9bd424ab59b6c3128eddb6850ba9eb9687d (diff)
downloaddeluge-da5d5bee209df81d6957aacb153eac00c9a457e6.tar.gz
deluge-da5d5bee209df81d6957aacb153eac00c9a457e6.tar.bz2
deluge-da5d5bee209df81d6957aacb153eac00c9a457e6.zip
[#3325|Core] Fix unable to remove magnet with delete_copies enabled
Users were encountering the following error while attempting to delete magnet torrents and had the config 'Delete copy of torrent file' enabled. This was due to removing a magnet before the metadata was downloaded and the torrent.filename was still set to None so raises exceptions when string operations are performed with it. File "/usr/lib/python3/dist-packages/deluge/core/torrent.py", line 1317, in delete_torrentfile os.path.join(self.config['torrentfiles_location'], self.filename) ... TypeError: join() argument must be str or bytes, not 'NoneType' Fixed by both setting a default empty string for self.filename and only deleting the torrent file copy if filename is set.
-rw-r--r--deluge/core/torrent.py5
-rw-r--r--deluge/tests/test_torrentmanager.py10
2 files changed, 14 insertions, 1 deletions
diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index be91b9da5..1676ff6ca 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -266,6 +266,9 @@ class Torrent(object):
self.is_finished = False
self.filename = filename
+ if not self.filename:
+ self.filename = ''
+
self.forced_error = None
self.statusmsg = None
self.state = None
@@ -1316,7 +1319,7 @@ class Torrent(object):
torrent_files = [
os.path.join(get_config_dir(), 'state', self.torrent_id + '.torrent')
]
- if delete_copies:
+ if delete_copies and self.filename:
torrent_files.append(
os.path.join(self.config['torrentfiles_location'], self.filename)
)
diff --git a/deluge/tests/test_torrentmanager.py b/deluge/tests/test_torrentmanager.py
index 5cb201984..20f824eb7 100644
--- a/deluge/tests/test_torrentmanager.py
+++ b/deluge/tests/test_torrentmanager.py
@@ -56,6 +56,16 @@ class TorrentmanagerTestCase(BaseTestCase):
)
self.assertTrue(self.tm.remove(torrent_id, False))
+ @defer.inlineCallbacks
+ def test_remove_magnet(self):
+ """Test remove magnet before received metadata and delete_copies is True"""
+ magnet = 'magnet:?xt=urn:btih:ab570cdd5a17ea1b61e970bb72047de141bce173'
+ options = {}
+ self.core.config.config['copy_torrent_file'] = True
+ self.core.config.config['del_copy_torrent_file'] = True
+ torrent_id = yield self.core.add_torrent_magnet(magnet, options)
+ self.assertTrue(self.tm.remove(torrent_id, False))
+
def test_prefetch_metadata(self):
from deluge._libtorrent import lt