From f403b5f3c87086010857e8322babf6bd4a691b03 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 29 Jun 2012 23:35:11 +0000 Subject: [PATCH] fix move_storage bugs --- ChangeLog | 1 + include/libtorrent/file.hpp | 2 ++ src/file.cpp | 21 ++++++++++++++++++++ src/storage.cpp | 38 +------------------------------------ 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index f20c86478..45c84edc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ * fix nagle implementation in uTP + * fix move_storage bugs * fix unnecessary dependency on boost.date_time when building boost.asio as separate compilation * always use SO_REUSEADDR and deprecate the flag to turn it on * add python bindings for SSL support diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 84d42c088..0f55e4556 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -124,6 +124,8 @@ namespace libtorrent TORRENT_EXPORT size_type file_size(std::string const& f); TORRENT_EXPORT bool is_directory(std::string const& f , error_code& ec); + TORRENT_EXPORT void recursive_copy(std::string const& old_path + , std::string const& new_path, error_code& ec); TORRENT_EXPORT void copy_file(std::string const& f , std::string const& newf, error_code& ec); diff --git a/src/file.cpp b/src/file.cpp index 83c066778..68b0a4af6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -268,6 +268,27 @@ namespace libtorrent return false; } + void recursive_copy(std::string const& old_path, std::string const& new_path, error_code& ec) + { + TORRENT_ASSERT(!ec); + if (is_directory(old_path, ec)) + { + create_directory(new_path, ec); + if (ec) return; + for (directory i(old_path, ec); !i.done(); i.next(ec)) + { + std::string f = i.file(); + if (f == ".." || f == ".") continue; + recursive_copy(combine_path(old_path, f), combine_path(new_path, f), ec); + if (ec) return; + } + } + else if (!ec) + { + copy_file(old_path, new_path, ec); + } + } + void copy_file(std::string const& inf, std::string const& newf, error_code& ec) { ec.clear(); diff --git a/src/storage.cpp b/src/storage.cpp index ad74a034e..8855f5e7b 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -115,42 +115,6 @@ namespace namespace libtorrent { - - void recursive_copy(std::string const& old_path, std::string const& new_path, error_code& ec) - { - TORRENT_ASSERT(!ec); - if (is_directory(old_path, ec)) - { - create_directory(new_path, ec); - if (ec) return; - for (directory i(old_path, ec); !i.done(); i.next(ec)) - { - std::string f = i.file(); - recursive_copy(f, combine_path(new_path, f), ec); - if (ec) return; - } - } - else if (!ec) - { - copy_file(old_path, new_path, ec); - } - } - - void recursive_remove(std::string const& old_path) - { - error_code ec; - if (is_directory(old_path, ec)) - { - for (directory i(old_path, ec); !i.done(); i.next(ec)) - recursive_remove(combine_path(old_path, i.file())); - remove(old_path, ec); - } - else - { - remove(old_path, ec); - } - } - std::vector > get_filesizes( file_storage const& storage, std::string const& p) { @@ -835,7 +799,7 @@ namespace libtorrent } else { - recursive_remove(old_path); + remove_all(old_path, ec); } break; }