forked from premiere/premiere-libtorrent
in case a regular rename fails, try to copy the storage to the new location. Fixes #231
This commit is contained in:
parent
4709d202e1
commit
59c8a74ba8
|
@ -252,7 +252,53 @@ namespace
|
|||
|
||||
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(
|
||||
file_storage const& s, fs::path p)
|
||||
{
|
||||
|
@ -781,10 +827,17 @@ namespace libtorrent
|
|||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::string err;
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue