From da5d5bee209df81d6957aacb153eac00c9a457e6 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Fri, 5 Feb 2021 18:55:54 +0000 Subject: [#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. --- deluge/core/torrent.py | 5 ++++- deluge/tests/test_torrentmanager.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 -- cgit