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.

This commit is contained in:
Andrew Resch 2009-11-20 19:13:12 +00:00
parent 634ecdeb1d
commit 1f58910a38
2 changed files with 24 additions and 14 deletions

View File

@ -75,16 +75,17 @@ def decode_string(s, encoding="utf8"):
class TorrentInfo(object): class TorrentInfo(object):
""" """
Collects information about a torrent file. Collects information about a torrent file.
:param filename: The path to the torrent :param filename: The path to the torrent
:type filename: string :type filename: string
""" """
def __init__(self, filename): def __init__(self, filename):
# Get the torrent data from the torrent file # Get the torrent data from the torrent file
try: try:
log.debug("Attempting to open %s.", filename) 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: except Exception, e:
log.warning("Unable to open %s: %s", filename, e) log.warning("Unable to open %s: %s", filename, e)
raise e raise e
@ -163,7 +164,7 @@ class TorrentInfo(object):
def name(self): def name(self):
""" """
The name of the torrent. The name of the torrent.
:rtype: string :rtype: string
""" """
return self.__m_name return self.__m_name
@ -172,7 +173,7 @@ class TorrentInfo(object):
def info_hash(self): def info_hash(self):
""" """
The torrents info_hash The torrents info_hash
:rtype: string :rtype: string
""" """
return self.__m_info_hash return self.__m_info_hash
@ -181,7 +182,7 @@ class TorrentInfo(object):
def files(self): def files(self):
""" """
A list of the files that the torrent contains. A list of the files that the torrent contains.
:rtype: list :rtype: list
""" """
return self.__m_files return self.__m_files
@ -190,15 +191,15 @@ class TorrentInfo(object):
def files_tree(self): def files_tree(self):
""" """
A dictionary based tree of the files. A dictionary based tree of the files.
:: ::
{ {
"some_directory": { "some_directory": {
"some_file": (index, size, download) "some_file": (index, size, download)
} }
} }
:rtype: dictionary :rtype: dictionary
""" """
return self.__m_files_tree return self.__m_files_tree
@ -207,11 +208,21 @@ class TorrentInfo(object):
def metadata(self): def metadata(self):
""" """
The torrents metadata. The torrents metadata.
:rtype: dictionary :rtype: dictionary
""" """
return self.__m_metadata 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): class FileTree(object):
""" """
Convert a list of paths in a file tree. Convert a list of paths in a file tree.
@ -219,7 +230,7 @@ class FileTree(object):
:param paths: The paths to be converted. :param paths: The paths to be converted.
:type paths: list :type paths: list
""" """
def __init__(self, paths): def __init__(self, paths):
self.tree = {} self.tree = {}

View File

@ -211,7 +211,7 @@ class AddTorrentDialog(component.Component):
new_row = self.torrent_liststore.append( new_row = self.torrent_liststore.append(
[info.info_hash, info.name, filename]) [info.info_hash, info.name, filename])
self.files[info.info_hash] = info.files 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.listview_torrents.get_selection().select_iter(new_row)
self.set_default_options() self.set_default_options()
@ -737,10 +737,9 @@ class AddTorrentDialog(component.Component):
del options["file_priorities"] del options["file_priorities"]
client.core.add_torrent_magnet(filename, options) client.core.add_torrent_magnet(filename, options)
else: else:
from deluge.bencode import bencode
client.core.add_torrent_file( client.core.add_torrent_file(
os.path.split(filename)[-1], os.path.split(filename)[-1],
base64.encodestring(bencode(self.infos[torrent_id])), base64.encodestring(self.infos[torrent_id]),
options) options)
row = self.torrent_liststore.iter_next(row) row = self.torrent_liststore.iter_next(row)