diff --git a/ChangeLog b/ChangeLog index 4a41f10ff..057e756ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix bug filename collision resolver + * fix bug in filename utf-8 verification * make need_save_resume() a bit more robust * fixed sparse flag manipulation on windows * fixed streaming piece picking issue diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index dda06eea4..9f02a9029 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -160,7 +160,7 @@ namespace libtorrent } // valid 4-byte utf-8 character - if ((i[0] & 0xf0) == 0xe0 + if ((i[0] & 0xf8) == 0xf0 && (i[1] & 0xc0) == 0x80 && (i[2] & 0xc0) == 0x80 && (i[3] & 0xc0) == 0x80) @@ -354,6 +354,13 @@ namespace libtorrent { if (list.type() != lazy_entry::list_t) return false; target.reserve(list.list_size()); + + // TODO: 1 this logic should be a separate step + // done once the torrent is loaded, and the original + // filenames should be preserved! + int cnt = 0; + std::set files; + for (int i = 0, end(list.list_size()); i < end; ++i) { lazy_entry const* file_hash = 0; @@ -364,20 +371,13 @@ namespace libtorrent , &file_hash, &fee, &mtime)) return false; - // TODO: 1 this logic should be a separate step - // done once the torrent is loaded, and the original - // filenames should be preserved! - int cnt = 0; - std::set files; - // as long as this file already exists // increase the counter - fprintf(stderr, "adding file: %s\n", e.path.c_str()); while (!files.insert(e.path).second) { ++cnt; char suffix[50]; - snprintf(suffix, sizeof(suffix), ".%d%s", cnt, extension(e.path).c_str()); + snprintf(suffix, sizeof(suffix), "%d%s", cnt, extension(e.path).c_str()); replace_extension(e.path, suffix); } target.add_file(e, file_hash ? file_hash->string_ptr() + info_ptr_diff : 0); diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index b690f68bd..6baeaa7f4 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -1392,6 +1392,12 @@ int test_main() comparison.resize(TORRENT_MAX_PATH); TEST_EQUAL(test, comparison); + + // replace_extension + test = "foo.bar"; + replace_extension(test, "txt"); + TEST_EQUAL(test, "foo.txt"); + // file class file f; #if TORRENT_USE_UNC_PATHS || !defined WIN32