diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 1aeded6b6..398c37873 100755 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -144,6 +144,8 @@ namespace libtorrent void operator=(const list_type&); void operator=(const integer_type&); + void sort(); + integer_type& integer(); const integer_type& integer() const; string_type& string(); diff --git a/src/entry.cpp b/src/entry.cpp index 2c2c4d94c..0ed5c1e87 100755 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -244,6 +244,18 @@ namespace libtorrent } } + void entry::sort() + { + using boost::bind; + if (type() == dictionary_t) + { + std::stable_sort(dict().begin(), dict().end() + , bind(std::less() + , bind(&entry::dictionary_type::value_type::first, _1) + , bind(&entry::dictionary_type::value_type::first, _2))); + } + } + void entry::print(std::ostream& os, int indent) const { assert(indent >= 0); diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 8c28477cf..930d47742 100755 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -399,6 +399,7 @@ namespace libtorrent { path_e.list().push_back(*j); } + file_e.sort(); } } @@ -414,6 +415,9 @@ namespace libtorrent { p.append((char*)i->begin(), (char*)i->end()); } + + info.sort(); + return info; } @@ -448,6 +452,8 @@ namespace libtorrent dict["info"] = create_info_metadata(); + dict.sort(); + return dict; }