diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index 957260620..ccf82621b 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -223,7 +223,7 @@ namespace libtorrent void rename_file(int index, std::string const& new_filename) { TORRENT_ASSERT(is_loaded()); - if (m_files.file_name(index) == new_filename) return; + if (m_files.file_path(index) == new_filename) return; copy_on_write(); m_files.rename_file(index, new_filename); } diff --git a/test/test_torrent.cpp b/test/test_torrent.cpp index b32b370bc..cef198ba3 100644 --- a/test/test_torrent.cpp +++ b/test/test_torrent.cpp @@ -264,4 +264,25 @@ TORRENT_TEST(torrent) } +TORRENT_TEST(rename_file) +{ + file_storage fs; + + fs.add_file("test3/tmp1", 0); + fs.add_file("test3/tmp2", 0); + libtorrent::create_torrent t(fs, 128 * 1024, 6); + + std::vector tmp; + std::back_insert_iterator > out(tmp); + bencode(out, t.generate()); + error_code ec; + boost::shared_ptr info(boost::make_shared(&tmp[0], tmp.size(), boost::ref(ec), 0)); + + TEST_EQUAL(info->files().file_path(0), "test3/tmp1"); + + // move "test3/tmp1" -> "tmp1" + info->rename_file(0, "tmp1"); + + TEST_EQUAL(info->files().file_path(0), "tmp1"); +}