From bc8e6b441fee8a34bddf39731eb8c74ab848f6a5 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Fri, 6 Jun 2008 07:27:35 +0000 Subject: [PATCH] add move to different partition --- libtorrent/src/storage.cpp | 60 +++++++++++++++++++++++++++++++-- plugins/MoveTorrent/__init__.py | 4 +-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index a0fa62b5a..57d90e5c0 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -252,6 +252,53 @@ namespace namespace libtorrent { + template + void recursive_copy(Path const& old_path, Path const& new_path, std::string& error) + { + using boost::filesystem::directory_iterator; +#ifndef BOOST_NO_EXCEPTIONS + try { +#endif + TORRENT_ASSERT(error.empty()); + if (is_directory(old_path)) + { + create_directory(new_path); + for (directory_iterator i(old_path), end; i != end; ++i) + { + recursive_copy(i->path(), new_path / i->leaf(), error); + if (!error.empty()) return; + } + } + else + { + copy_file(old_path, new_path); + } +#ifndef BOOST_NO_EXCEPTIONS + } catch (std::exception& e) { error = e.what(); } +#endif + } + + template + void recursive_remove(Path const& old_path) + { + using boost::filesystem::directory_iterator; +#ifndef BOOST_NO_EXCEPTIONS + try { +#endif + if (is_directory(old_path)) + { + for (directory_iterator i(old_path), end; i != end; ++i) + recursive_remove(i->path()); + remove(old_path); + } + else + { + remove(old_path); + } +#ifndef BOOST_NO_EXCEPTIONS + } catch (std::exception& e) {} +#endif + } std::vector > get_filesizes( torrent_info const& t, fs::path p) { @@ -667,8 +714,17 @@ namespace libtorrent m_save_path = save_path; return true; } - catch (std::exception&) {} - return false; + catch (std::exception& e) + { + std::string err; + recursive_copy(old_path, new_path, err); + if (!err.empty()) + { + return true; + } + m_save_path = save_path; + recursive_remove(old_path); + } } #ifndef NDEBUG diff --git a/plugins/MoveTorrent/__init__.py b/plugins/MoveTorrent/__init__.py index 7331afcfc..b96b9e715 100644 --- a/plugins/MoveTorrent/__init__.py +++ b/plugins/MoveTorrent/__init__.py @@ -23,7 +23,7 @@ plugin_description = _("This plugin allows users to move the torrent to a \ different directory without having to remove and re-add the torrent. This \ feature can be found by right-clicking on a torrent.\nFurthermore, it \ allows the user to automatically have finished torrents moved to a different \ -folder.\nNote: Files can currently only be moved within the same partition") +folder.") def deluge_init(deluge_path): global path @@ -130,7 +130,7 @@ class movetorrentMenu: def handle_event(self, event): if event['event_type'] is self.core.constants['EVENT_STORAGE_MOVED']: if event['message'] == self.core.unique_IDs[event['unique_ID']].save_dir: - self.dialogs.show_popup_warning(self.window, _("You cannot move torrent to a different partition. Please check your preferences. Also, you cannot move a torrent's files to the same directory that they are already stored or move a torrent's files before any of its files have actually been created.")) + self.dialogs.show_popup_warning(self.window, "An error occured while trying to move the torrent. Please check your permissions and note that you cannot move a torrent's files to the same directory that they are already stored or move a torrent's files before any of its files have actually been created.")) self.core.unique_IDs[event['unique_ID']].save_dir = event['message'] self.core.pickle_state()