diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 01d069144..954b93b32 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2) #define TORRENT_SEPARATOR '\\' @@ -663,7 +664,9 @@ namespace { // TODO: 3 this is a hack to retain ABI compatibility with 1.2.1 // in next major release, make this return by value - static std::string ret; + static std::string storage[4]; + static std::atomic counter{0}; + std::string& ret = storage[(counter++) % 4]; ret.reserve(m_name.size() + link.size() + 1); ret.assign(m_name); append_path(ret, link); diff --git a/test/test_file_storage.cpp b/test/test_file_storage.cpp index 415cf6d89..ea86aa03c 100644 --- a/test/test_file_storage.cpp +++ b/test/test_file_storage.cpp @@ -753,6 +753,28 @@ TORRENT_TEST(sanitize_symlinks_circular) TEST_EQUAL(fs.symlink(file_index_t{2}), "test" SEP "2"); } +TORRENT_TEST(query_symlinks) +{ + file_storage fs; + fs.set_piece_length(1024); + fs.add_file("test/0", 0, file_storage::flag_symlink, 0, "0"); + fs.add_file("test/1", 0, file_storage::flag_symlink, 0, "1"); + fs.add_file("test/2", 0, file_storage::flag_symlink, 0, "2"); + fs.add_file("test/3", 0, file_storage::flag_symlink, 0, "3"); + + auto const& ret1 = fs.symlink(file_index_t{0}); + auto const& ret2 = fs.symlink(file_index_t{1}); + auto const& ret3 = fs.symlink(file_index_t{2}); + auto const& ret4 = fs.symlink(file_index_t{3}); + + TEST_CHECK(ret1 != ret2); + TEST_CHECK(ret1 != ret3); + TEST_CHECK(ret1 != ret4); + TEST_CHECK(ret2 != ret3); + TEST_CHECK(ret2 != ret4); + TEST_CHECK(ret3 != ret4); +} + // TODO: test file attributes // TODO: test symlinks // TODO: test reorder_file (make sure internal_file_entry::swap() is used)