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

@ -84,7 +84,8 @@ class TorrentInfo(object):
# 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
@ -212,6 +213,16 @@ class TorrentInfo(object):
"""
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.

View File

@ -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)