Fix for adding torrents with invalid filename encodings

This commit is contained in:
Andrew Resch 2009-04-10 17:34:55 +00:00
parent 2023fac5c5
commit 1693bc7373
4 changed files with 11 additions and 6 deletions

View file

@ -1,6 +1,7 @@
=== Deluge 1.1.7 - (In Development) ===
==== GtkUI ====
* Fix #883 segfault if locale is not using UTF-8 encoding
* Fix for adding torrents with invalid filename encodings
=== Deluge 1.1.6 - (06 April 2009) ===
==== Core ====

View file

@ -271,13 +271,17 @@ class BaseClient(object):
# Open the .torrent file for reading because we need to send it's
# contents to the core.
try:
f = open(unicode(torrent_file), "rb")
f = open(torrent_file, "rb")
except Exception, e:
log.warning("Unable to open %s: %s", torrent_file, e)
continue
# Get the filename because the core doesn't want a path.
(path, filename) = os.path.split(torrent_file)
# Get the name of the torrent from the TorrentInfo object because
# it does better handling of encodings
import deluge.ui.common
ti = deluge.ui.common.TorrentInfo(torrent_file)
filename = ti.name
fdump = xmlrpclib.Binary(f.read())
f.close()

View file

@ -62,6 +62,8 @@ class TorrentInfo(object):
self.encoding = "UTF-8"
if "encoding" in self.__m_metadata:
self.encoding = self.__m_metadata["encoding"]
elif "codepage" in self.__m_metadata:
self.encoding = str(self.__m_metadata["codepage"])
# Get list of files from torrent info
self.__m_files = []

View file

@ -186,14 +186,12 @@ class AddTorrentDialog(component.Component):
new_row = None
for filename in filenames:
# Convert the path to unicode
filename = unicode(filename)
# Get the torrent data from the torrent file
try:
info = deluge.ui.common.TorrentInfo(filename)
except Exception, e:
log.debug("Unable to open torrent file: %s", e)
log.exception(e)
continue
if info.info_hash in self.files: