diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 4e45d5687..9af981a72 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -260,6 +260,8 @@ namespace libtorrent typedef std::list cache_t; bool test_error(disk_io_job& j); + void post_callback(boost::function const& handler + , disk_io_job const& j, int ret); // cache operations cache_t::iterator find_cached_piece( diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 4c03ed6b7..3662a677f 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -292,14 +292,13 @@ namespace libtorrent } if (i->action == disk_io_job::read) { - if (i->callback) m_ios.post(bind(i->callback, -1, *i)); + post_callback(i->callback, *i, -1); m_jobs.erase(i++); continue; } if (i->action == disk_io_job::check_files) { - if (i->callback) m_ios.post(bind(i->callback - , piece_manager::disk_check_aborted, *i)); + post_callback(i->callback, *i, piece_manager::disk_check_aborted); m_jobs.erase(i++); continue; } @@ -1006,6 +1005,15 @@ namespace libtorrent return false; } + void disk_io_thread::post_callback( + boost::function const& handler + , disk_io_job const& j, int ret) + { + if (!handler) return; + + m_ios.post(bind(handler, ret, j)); + } + void disk_io_thread::operator()() { for (;;) @@ -1103,8 +1111,7 @@ namespace libtorrent } if (i->action == disk_io_job::check_files) { - if (i->callback) m_ios.post(bind(i->callback - , piece_manager::disk_check_aborted, *i)); + post_callback(i->callback, *i, piece_manager::disk_check_aborted); m_jobs.erase(i++); continue; } @@ -1125,14 +1132,13 @@ namespace libtorrent { if (i->action == disk_io_job::read) { - if (i->callback) m_ios.post(bind(i->callback, -1, *i)); + post_callback(i->callback, *i, -1); m_jobs.erase(i++); continue; } if (i->action == disk_io_job::check_files) { - if (i->callback) m_ios.post(bind(i->callback - , piece_manager::disk_check_aborted, *i)); + post_callback(i->callback, *i, piece_manager::disk_check_aborted); m_jobs.erase(i++); continue; } @@ -1314,7 +1320,7 @@ namespace libtorrent m_log << log_time() << " move" << std::endl; #endif TORRENT_ASSERT(j.buffer == 0); - ret = j.storage->move_storage_impl(j.str) ? 0 : 1; + ret = j.storage->move_storage_impl(j.str); if (ret != 0) { test_error(j); @@ -1438,7 +1444,7 @@ namespace libtorrent #endif TORRENT_ASSERT(handler); if (handler && ret == piece_manager::need_full_check) - m_ios.post(bind(handler, ret, j)); + post_callback(handler, j, ret); #ifndef BOOST_NO_EXCEPTIONS } catch (std::exception&) {} #endif @@ -1497,7 +1503,7 @@ namespace libtorrent #endif TORRENT_ASSERT(ret != -2 || !j.str.empty() || j.action == disk_io_job::hash); - if (handler) m_ios.post(bind(handler, ret, j)); + post_callback(handler, j, ret); #ifndef BOOST_NO_EXCEPTIONS } catch (std::exception&) { diff --git a/src/storage.cpp b/src/storage.cpp index 3f9db94ab..c54da57c9 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -962,7 +962,10 @@ namespace libtorrent set_error(m_save_path / files().name(), ec); ret = false; } - recursive_remove(old_path); + else + { + recursive_remove(old_path); + } } #endif } diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 2c6fa8dd9..d1ee095df 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -114,6 +114,8 @@ void run_storage_tests(boost::intrusive_ptr info { TORRENT_ASSERT(fs.num_files() > 0); create_directory(test_path / "temp_storage"); + remove_all(test_path / "temp_storage2"); + remove_all(test_path / "part0"); int num_pieces = fs.num_pieces(); TEST_CHECK(info->num_pieces() == num_pieces); @@ -211,6 +213,7 @@ void run_storage_tests(boost::intrusive_ptr info ios.poll(ec); TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp")); + TEST_CHECK(!exists(test_path / "temp_storage2")); TEST_CHECK(exists(test_path / "part0")); // test move_storage with two files in the root directory