diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 394e3c21c..48a9baf4f 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -829,11 +829,20 @@ void scan_dir(std::string const& dir_path using namespace libtorrent; error_code ec; + std::vector > ents; // TODO: don't use internal directory type for (directory i(dir_path, ec); !i.done(); i.next(ec)) { - std::string file = combine_path(dir_path, i.file()); - if (extension(file) != ".torrent") continue; + if (extension(i.file()) != ".torrent") continue; + ents.push_back(std::make_pair(i.inode(), i.file())); + } + + std::sort(ents.begin(), ents.end()); + + for (std::vector >::iterator i = ents.begin() + , end(ents.end()); i != end; ++i) + { + std::string file = combine_path(dir_path, i->second); handles_t::iterator k = files.find(file); if (k != files.end()) diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index ecdb45cb1..e26ba68b0 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -160,10 +160,12 @@ namespace libtorrent ~directory(); void next(error_code& ec); std::string file() const; + boost::uint64_t inode() const; bool done() const { return m_done; } private: #ifdef TORRENT_WINDOWS HANDLE m_handle; + int m_inode; #if TORRENT_USE_WSTRING WIN32_FIND_DATAW m_fd; #else diff --git a/src/file.cpp b/src/file.cpp index d99b11ef8..6d2632c8d 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -793,6 +793,7 @@ namespace libtorrent { ec.clear(); #ifdef TORRENT_WINDOWS + m_inode = 0; // the path passed to FindFirstFile() must be // a pattern std::string f = convert_separators(path); @@ -846,6 +847,15 @@ namespace libtorrent #endif } + boost::uint64_t directory::inode() const + { +#ifdef TORRENT_WINDOWS + return m_inode; +#else + return m_dirent.d_ino; +#endif + } + std::string directory::file() const { #ifdef TORRENT_WINDOWS @@ -875,6 +885,7 @@ namespace libtorrent if (err != ERROR_NO_MORE_FILES) ec.assign(err, boost::system::get_system_category()); } + ++m_inode; #else dirent* dummy; if (readdir_r(m_handle, &m_dirent, &dummy) != 0)