diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index cafec162c..85433e533 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -885,31 +885,32 @@ 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) + self.torrent_id, dest) 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 @@ -985,8 +986,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 b3c6d4cba..bb6605569 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -452,9 +452,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 diff --git a/deluge/ui/gtkui/createtorrentdialog.py b/deluge/ui/gtkui/createtorrentdialog.py index acfc06097..435cba0a6 100644 --- a/deluge/ui/gtkui/createtorrentdialog.py +++ b/deluge/ui/gtkui/createtorrentdialog.py @@ -174,7 +174,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)]) @@ -202,7 +202,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)])