From 1f58910a3841f206f7de6ad605c9035312b1baf2 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 20 Nov 2009 19:13:12 +0000 Subject: [PATCH] Fix adding torrents with different metadata by storing the bencoded dict too. If we bencode the stored metadata dict, there is a chance the order of the dict will be different and change the info-hash. --- deluge/ui/common.py | 33 +++++++++++++++++++---------- deluge/ui/gtkui/addtorrentdialog.py | 5 ++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 1748f201a..4ea999da8 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -75,16 +75,17 @@ def decode_string(s, encoding="utf8"): class TorrentInfo(object): """ Collects information about a torrent file. - + :param filename: The path to the torrent :type filename: string - + """ def __init__(self, filename): # Get the torrent data from the torrent file try: log.debug("Attempting to open %s.", filename) - self.__m_metadata = bencode.bdecode(open(filename, "rb").read()) + self.__m_filedata = open(filename, "rb").read() + self.__m_metadata = bencode.bdecode(self.__m_filedata) except Exception, e: log.warning("Unable to open %s: %s", filename, e) raise e @@ -163,7 +164,7 @@ class TorrentInfo(object): def name(self): """ The name of the torrent. - + :rtype: string """ return self.__m_name @@ -172,7 +173,7 @@ class TorrentInfo(object): def info_hash(self): """ The torrents info_hash - + :rtype: string """ return self.__m_info_hash @@ -181,7 +182,7 @@ class TorrentInfo(object): def files(self): """ A list of the files that the torrent contains. - + :rtype: list """ return self.__m_files @@ -190,15 +191,15 @@ class TorrentInfo(object): def files_tree(self): """ A dictionary based tree of the files. - + :: - + { "some_directory": { "some_file": (index, size, download) } } - + :rtype: dictionary """ return self.__m_files_tree @@ -207,11 +208,21 @@ class TorrentInfo(object): def metadata(self): """ The torrents metadata. - + :rtype: dictionary """ return self.__m_metadata + @property + def filedata(self): + """ + The torrents file data. This will be the bencoded dictionary read + from the torrent file. + + :rtype: string + """ + return self.__m_filedata + class FileTree(object): """ Convert a list of paths in a file tree. @@ -219,7 +230,7 @@ class FileTree(object): :param paths: The paths to be converted. :type paths: list """ - + def __init__(self, paths): self.tree = {} diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 8f52c362b..fb253c6bf 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -211,7 +211,7 @@ class AddTorrentDialog(component.Component): new_row = self.torrent_liststore.append( [info.info_hash, info.name, filename]) self.files[info.info_hash] = info.files - self.infos[info.info_hash] = info.metadata + self.infos[info.info_hash] = info.filedata self.listview_torrents.get_selection().select_iter(new_row) self.set_default_options() @@ -737,10 +737,9 @@ class AddTorrentDialog(component.Component): del options["file_priorities"] client.core.add_torrent_magnet(filename, options) else: - from deluge.bencode import bencode client.core.add_torrent_file( os.path.split(filename)[-1], - base64.encodestring(bencode(self.infos[torrent_id])), + base64.encodestring(self.infos[torrent_id]), options) row = self.torrent_liststore.iter_next(row)