in case a regular rename fails, try to copy the storage to the new location. Fixes #231
This commit is contained in:
@@ -252,7 +252,53 @@ namespace
|
|||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
template <class Path>
|
||||||
|
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 <class Path>
|
||||||
|
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<std::pair<size_type, std::time_t> > get_filesizes(
|
std::vector<std::pair<size_type, std::time_t> > get_filesizes(
|
||||||
file_storage const& s, fs::path p)
|
file_storage const& s, fs::path p)
|
||||||
{
|
{
|
||||||
@@ -782,8 +828,15 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
set_error((m_save_path / files().name()).string(), e.what());
|
std::string err;
|
||||||
return true;
|
recursive_copy(old_path, new_path, err);
|
||||||
|
if (!err.empty())
|
||||||
|
{
|
||||||
|
set_error((m_save_path / files().name()).string(), e.what());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
m_save_path = save_path;
|
||||||
|
recursive_remove(old_path);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user