diff options
author | Chase Sterling <chase.sterling@gmail.com> | 2012-11-19 19:34:19 -0500 |
---|---|---|
committer | Chase Sterling <chase.sterling@gmail.com> | 2012-11-21 01:25:18 -0500 |
commit | 7d88cb1850eaf4d15646bdbf919b4451de0cbfea (patch) | |
tree | 6a9c5f81cab99b6b881a168fac07f3beb87bc278 /deluge/core/torrent.py | |
parent | d825be4901236323c9c8ef1cc5626436654bbe83 (diff) | |
download | deluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.tar.gz deluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.tar.bz2 deluge-7d88cb1850eaf4d15646bdbf919b4451de0cbfea.zip |
Fix file renaming and moving with unicode characters on libtorrent 0.16
Fix torrent creation with unicode characters
Update changelog
Diffstat (limited to 'deluge/core/torrent.py')
-rw-r--r-- | deluge/core/torrent.py | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 7e7f955b7..027077c23 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 |