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):
"""
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 = {}

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)