merged rename_file fix from RC_0_16

This commit is contained in:
Arvid Norberg 2013-02-09 21:50:22 +00:00
parent eb0f636ab1
commit d63b82bb78
3 changed files with 29 additions and 3 deletions

View File

@ -15,6 +15,7 @@
0.16.8 release 0.16.8 release
* make rename_file create missing directories for new filename
* added missing python function: parse_magnet_uri * added missing python function: parse_magnet_uri
* fix alerts.all_categories in python binding * fix alerts.all_categories in python binding
* fix torrent-abort issue which would cancel name lookups of other torrents * fix torrent-abort issue which would cancel name lookups of other torrents

View File

@ -503,8 +503,23 @@ namespace libtorrent
m_pool.release(this, index); m_pool.release(this, index);
error_code ec; error_code ec;
rename(old_name, combine_path(m_save_path, new_filename), ec); std::string new_path = combine_path(m_save_path, new_filename);
std::string new_dir = parent_path(new_path);
// create any missing directories that the new filename
// lands in
create_directories(new_dir, ec);
if (ec)
{
set_error(new_dir, ec);
return true;
}
rename(old_name, new_path, ec);
// if old_name doesn't exist, that's not an error
// here. Once we start writing to the file, it will
// be written to the new filename
if (ec && ec != boost::system::errc::no_such_file_or_directory) if (ec && ec != boost::system::errc::no_such_file_or_directory)
{ {
set_error(old_name, ec); set_error(old_name, ec);

View File

@ -547,13 +547,23 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
// test rename_file // test rename_file
remove(combine_path(test_path, "part0"), ec); remove(combine_path(test_path, "part0"), ec);
if (ec) std::cerr << "remove: " << ec.message() << std::endl; if (ec) std::cerr << "remove: " << ec.message() << std::endl;
remove_all(combine_path(test_path, "test_dir"), ec);
if (ec) std::cerr << "remove: " << ec.message() << std::endl;
TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp"))); TEST_CHECK(exists(combine_path(test_path, "temp_storage/test1.tmp")));
TEST_CHECK(!exists(combine_path(test_path, "part0"))); TEST_CHECK(!exists(combine_path(test_path, "part0")));
boost::function<void(int, disk_io_job const&)> none; TEST_CHECK(!exists(combine_path(test_path, "test_dir/subdir/part0")));
// test that we can create missing directories when we rename a file
done = false;
pm->async_rename_file(0, "test_dir/subdir/part0", boost::bind(&signal_bool, &done, "rename_file"));
run_until(ios, done);
TEST_CHECK(!exists(combine_path(test_path, "temp_storage/test1.tmp")));
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2")));
TEST_CHECK(exists(combine_path(test_path, "test_dir/subdir/part0")));
done = false; done = false;
pm->async_rename_file(0, "part0", boost::bind(&signal_bool, &done, "rename_file")); pm->async_rename_file(0, "part0", boost::bind(&signal_bool, &done, "rename_file"));
run_until(ios, done); run_until(ios, done);
TEST_CHECK(!exists(combine_path(test_path, "temp_storage/test1.tmp"))); TEST_CHECK(!exists(combine_path(test_path, "temp_storage/test1.tmp")));
TEST_CHECK(!exists(combine_path(test_path, "temp_storage2"))); TEST_CHECK(!exists(combine_path(test_path, "temp_storage2")));
TEST_CHECK(exists(combine_path(test_path, "part0"))); TEST_CHECK(exists(combine_path(test_path, "part0")));