summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChase Sterling <chase.sterling@gmail.com>2012-11-19 19:34:19 -0500
committerChase Sterling <chase.sterling@gmail.com>2012-11-21 01:25:18 -0500
commit7d88cb1850eaf4d15646bdbf919b4451de0cbfea (patch)
tree6a9c5f81cab99b6b881a168fac07f3beb87bc278
parentd825be4901236323c9c8ef1cc5626436654bbe83 (diff)
downloaddeluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.zip
deluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.tar.gz
deluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.tar.bz2
Fix file renaming and moving with unicode characters on libtorrent 0.16
Fix torrent creation with unicode characters Update changelog
-rw-r--r--ChangeLog2
-rw-r--r--deluge/core/torrent.py42
-rw-r--r--deluge/core/torrentmanager.py9
-rw-r--r--deluge/ui/gtkui/createtorrentdialog.py4
4 files changed, 38 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 880af4d..8a18c04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 ====
diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index 7e7f955..027077c 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -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
diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py
index 275c185..c39a72b 100644
--- a/deluge/core/torrentmanager.py
+++ b/deluge/core/torrentmanager.py
@@ -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"] = ""
diff --git a/deluge/ui/gtkui/createtorrentdialog.py b/deluge/ui/gtkui/createtorrentdialog.py
index 38f1078..314dda1 100644
--- a/deluge/ui/gtkui/createtorrentdialog.py
+++ b/deluge/ui/gtkui/createtorrentdialog.py
@@ -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)])