From e70e43e631ba1ad3ebec0bd30b4d8c88e80d552d Mon Sep 17 00:00:00 2001 From: bendikro Date: Thu, 25 May 2023 08:30:50 +0200 Subject: [PATCH] [GTKUI] Add torrent dialog incorrectly removes dir When adding a torrent in the add torrents dialog, containing only a single directory with a single file inside, the directory is not included as a prefix to the filename. The prefix is added only if there are multiple files inside the directory. Fix by adding the prefix also when there is only one file inside a dir. Closes: https://dev.deluge-torrent.org/ticket/3602 Closes: https://github.com/deluge-torrent/deluge/pull/424 --- deluge/tests/data/dir_with_single_file.torrent | 1 + deluge/tests/test_ui_common.py | 16 ++++++++++++++++ deluge/ui/common.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 deluge/tests/data/dir_with_single_file.torrent diff --git a/deluge/tests/data/dir_with_single_file.torrent b/deluge/tests/data/dir_with_single_file.torrent new file mode 100644 index 000000000..33fec2c5f --- /dev/null +++ b/deluge/tests/data/dir_with_single_file.torrent @@ -0,0 +1 @@ +d10:created by13:mktorrent 1.113:creation datei1684991433e4:infod5:filesld6:lengthi9e4:pathl15:single_file.txteee4:name20:dir_with_single_file12:piece lengthi262144e6:pieces20:Wi,=35Yhee \ No newline at end of file diff --git a/deluge/tests/test_ui_common.py b/deluge/tests/test_ui_common.py index ee97259de..fc56ebc03 100644 --- a/deluge/tests/test_ui_common.py +++ b/deluge/tests/test_ui_common.py @@ -157,3 +157,19 @@ class TestUICommon: ] assert len(ti.files) == len(result_files) + + def test_directory_with_single_file(self): + filename = common.get_test_data_file('dir_with_single_file.torrent') + + ti = TorrentInfo(filename) + expected_file_tree = {'dir_with_single_file': {'single_file.txt': (0, 9, True)}} + assert ti.files_tree == expected_file_tree + + result_files = [ + { + 'path': 'dir_with_single_file/single_file.txt', + 'size': 9, + 'download': True, + } + ] + assert ti.files == result_files diff --git a/deluge/ui/common.py b/deluge/ui/common.py index f9f774e23..e9b445d97 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -216,7 +216,7 @@ class TorrentInfo: if 'files' in info_dict: paths = {} dirs = {} - prefix = self._name if len(info_dict['files']) > 1 else '' + prefix = self._name for index, f in enumerate(info_dict['files']): f = {k.decode(): v for k, v in f.items()}