summaryrefslogtreecommitdiffstats
path: root/deluge/ui/common.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2020-06-14 19:04:29 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2021-03-24 10:26:08 +0000
commit3ec23ad96bfa205c8ae23b662c6da153efbfed3a (patch)
tree880c8efcea5253b330b443f3d99e7118a9da11ca /deluge/ui/common.py
parentdcd3918f3626403e32f00993d0a6e7014be3cbf3 (diff)
downloaddeluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.tar.gz
deluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.tar.bz2
deluge-3ec23ad96bfa205c8ae23b662c6da153efbfed3a.zip
[#3388|WebUI] Fix md5sums in torrent files breaking file listing
Torrents containing md5sum optional hashes are not being decoded and so causes errors in the json_api when the TorrentInfo is returned: Object of type bytes is not JSON serializable Fixed by removing all optional hashes from the paths returned from TorrentInfo and only including the required path keys. The optional hashes are unused by Deluge so simplify by removing. Fixed Windows path issue in TorrentInfo by ensuring conversion to posix paths. Refs: http://wiki.bitcomet.com/inside_bitcomet http://wiki.depthstrike.com/index.php/P2P:Protocol:Specifications:Optional_Hashes https://wiki.theory.org/index.php/BitTorrentSpecification
Diffstat (limited to 'deluge/ui/common.py')
-rw-r--r--deluge/ui/common.py27
1 files changed, 8 insertions, 19 deletions
diff --git a/deluge/ui/common.py b/deluge/ui/common.py
index 21bcafd5f..9af1d50bd 100644
--- a/deluge/ui/common.py
+++ b/deluge/ui/common.py
@@ -15,7 +15,6 @@ from __future__ import unicode_literals
import logging
import os
-from binascii import hexlify
from hashlib import sha1 as sha
from deluge import bencode
@@ -206,12 +205,9 @@ class TorrentInfo(object):
self._info_hash = sha(bencode.bencode(info_dict)).hexdigest()
# Get encoding from torrent file if available
- encoding = info_dict.get('encoding', None)
- codepage = info_dict.get('codepage', None)
- if not encoding:
- encoding = codepage if codepage else b'UTF-8'
- if encoding:
- encoding = encoding.decode()
+ encoding = info_dict.get(
+ 'encoding', info_dict.get('codepage', b'UTF-8')
+ ).decode()
# Decode 'name' with encoding unless 'name.utf-8' found.
if 'name.utf-8' in info_dict:
@@ -231,27 +227,20 @@ class TorrentInfo(object):
if 'path.utf-8' in f:
path = decode_bytes(os.path.join(*f['path.utf-8']))
- del f['path.utf-8']
else:
path = decode_bytes(os.path.join(*f['path']), encoding)
if prefix:
path = os.path.join(prefix, path)
+ # Ensure agnostic path separator
+ path = path.replace('\\', '/')
+
self._files.append(
{'path': path, 'size': f['length'], 'download': True}
)
+ paths[path] = {'path': path, 'index': index, 'length': f['length']}
- f['path'] = path
- f['index'] = index
- if 'sha1' in f and len(f['sha1']) == 20:
- f['sha1'] = hexlify(f['sha1']).decode()
- if 'ed2k' in f and len(f['ed2k']) == 16:
- f['ed2k'] = hexlify(f['ed2k']).decode()
- if 'filehash' in f and len(f['filehash']) == 20:
- f['filehash'] = hexlify(f['filehash']).decode()
-
- paths[path] = f
dirname = os.path.dirname(path)
while dirname:
dirinfo = dirs.setdefault(dirname, {})
@@ -538,7 +527,7 @@ class FileTree(object):
def walk(directory, parent_path):
for path in list(directory):
- full_path = os.path.join(parent_path, path)
+ full_path = os.path.join(parent_path, path).replace('\\', '/')
if isinstance(directory[path], dict):
directory[path] = (
callback(full_path, directory[path]) or directory[path]