Fix file renaming and moving with unicode characters on libtorrent 0.16

Fix torrent creation with unicode characters

Update changelog
This commit is contained in:
Chase Sterling 2012-11-19 19:34:19 -05:00
parent d825be4901
commit 7d88cb1850
4 changed files with 38 additions and 19 deletions

View File

@ -1,10 +1,12 @@
=== Deluge 1.3.6 (In Development) ===
==== Core ====
* Catch & log KeyError when removing a torrent from the queued torrents set
* Fix moving/renaming torrents with non-ascii characters in libtorrent 0.16
==== GtkUI ====
* Add move completed option to add torrent dialog
* Prevent jitter in torrent view
* Fix torrent creation with non-ascii characters
=== Deluge 1.3.5 (09 April 2012) ===
==== Core ====

View File

@ -834,29 +834,30 @@ class Torrent(object):
def move_storage(self, dest):
"""Move a torrent's storage location"""
if deluge.common.windows_check():
# Attempt to convert utf8 path to unicode
# Note: Inconsistent encoding for 'dest', needs future investigation
try:
dest_u = unicode(dest, "utf-8")
except TypeError:
# String is already unicode
dest_u = dest
else:
dest_u = dest
try:
dest = unicode(dest, "utf-8")
except TypeError:
# String is already unicode
pass
if not os.path.exists(dest_u):
if not os.path.exists(dest):
try:
# Try to make the destination path if it doesn't exist
os.makedirs(dest_u)
os.makedirs(dest)
except IOError, e:
log.exception(e)
log.error("Could not move storage for torrent %s since %s does not exist and could not create the directory.", self.torrent_id, dest_u)
return False
dest_bytes = dest.encode('utf-8')
try:
self.handle.move_storage(dest_u)
except:
# libtorrent needs unicode object if wstrings are enabled, utf8 bytestring otherwise
try:
self.handle.move_storage(dest)
except TypeError:
self.handle.move_storage(dest_bytes)
except Exception, e:
log.error("Error calling libtorrent move_storage: %s" % e)
return False
return True
@ -932,8 +933,17 @@ class Torrent(object):
"""Renames files in the torrent. 'filenames' should be a list of
(index, filename) pairs."""
for index, filename in filenames:
# Make sure filename is a unicode object
try:
filename = unicode(filename, "utf-8")
except TypeError:
pass
filename = sanitize_filepath(filename)
self.handle.rename_file(index, filename.encode("utf-8"))
# libtorrent needs unicode object if wstrings are enabled, utf8 bytestring otherwise
try:
self.handle.rename_file(index, filename)
except TypeError:
self.handle.rename_file(index, filename.encode("utf-8"))
def rename_folder(self, folder, new_folder):
"""Renames a folder within a torrent. This basically does a file rename

View File

@ -419,9 +419,16 @@ class TorrentManager(component.Component):
# before adding to the session.
if options["mapped_files"]:
for index, fname in options["mapped_files"].items():
try:
fname = unicode(fname, "utf-8")
except TypeError:
pass
fname = deluge.core.torrent.sanitize_filepath(fname)
log.debug("renaming file index %s to %s", index, fname)
torrent_info.rename_file(index, utf8_encoded(fname))
try:
torrent_info.rename_file(index, fname)
except TypeError:
torrent_info.rename_file(index, fname.encode("utf-8"))
add_torrent_params["ti"] = torrent_info
add_torrent_params["resume_data"] = ""

View File

@ -159,7 +159,7 @@ class CreateTorrentDialog:
chooser.destroy()
return
path = result.decode('utf-8').encode(sys.getfilesystemencoding())
path = result.decode('utf-8')
self.files_treestore.clear()
self.files_treestore.append(None, [result, gtk.STOCK_FILE, deluge.common.get_path_size(path)])
@ -187,7 +187,7 @@ class CreateTorrentDialog:
chooser.destroy()
return
path = result.decode('utf-8').encode(sys.getfilesystemencoding())
path = result.decode('utf-8')
self.files_treestore.clear()
self.files_treestore.append(None, [result, gtk.STOCK_OPEN, deluge.common.get_path_size(path)])