fix move_storage bugs

This commit is contained in:
Arvid Norberg 2012-06-29 23:35:11 +00:00
parent b14479132c
commit f403b5f3c8
4 changed files with 25 additions and 37 deletions

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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<std::pair<size_type, std::time_t> > 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;
}