From 357d548bb5049631a0ed699ba5927600c92edfe8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 21 Nov 2008 23:38:07 +0000 Subject: [PATCH] fixed boost.filesystem usage to not rely on deprecated functions --- examples/client_test.cpp | 2 +- examples/make_torrent.cpp | 2 -- include/libtorrent/create_torrent.hpp | 8 ++++++-- src/file.cpp | 6 +++--- src/storage.cpp | 16 ++++++++-------- test/setup_transfer.cpp | 3 ++- test/test_storage.cpp | 2 +- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 016ec39fc..0fd6ea75d 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -551,7 +551,7 @@ void scan_dir(path const& dir_path for (directory_iterator i(dir_path), end; i != end; ++i) { if (extension(*i) != ".torrent") continue; - std::string file = i->string(); + std::string file = i->path().string(); handles_t::iterator k = handles.find(file); if (k != handles.end()) diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index 241455c0c..1b9ff7cdb 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -73,8 +73,6 @@ int main(int argc, char* argv[]) int piece_size = 256 * 1024; char const* creator_str = "libtorrent"; - path::default_name_check(no_check); - if (argc != 4 && argc != 5) { std::cerr << "usage: make_torrent " diff --git a/include/libtorrent/create_torrent.hpp b/include/libtorrent/create_torrent.hpp index 58ec8092e..79c030b81 100644 --- a/include/libtorrent/create_torrent.hpp +++ b/include/libtorrent/create_torrent.hpp @@ -161,9 +161,9 @@ namespace libtorrent { for (directory_iterator i(f), end; i != end; ++i) #if BOOST_VERSION < 103600 - add_files_impl(fs, p, l / i->leaf(), pred); + add_files_impl(fs, p, l / i->path().leaf(), pred); #else - add_files_impl(fs, p, l / i->filename(), pred); + add_files_impl(fs, p, l / i->path().filename(), pred); #endif } else @@ -185,7 +185,11 @@ namespace libtorrent inline void add_files(file_storage& fs, boost::filesystem::path const& file) { +#if BOOST_VERSION < 103600 detail::add_files_impl(fs, complete(file).branch_path(), file.leaf(), detail::default_pred); +#else + detail::add_files_impl(fs, complete(file).parent_path(), file.filename(), detail::default_pred); +#endif } template diff --git a/src/file.cpp b/src/file.cpp index 0ca89ca73..23147edf1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -139,9 +139,9 @@ namespace libtorrent #ifdef TORRENT_WINDOWS #ifdef UNICODE - std::wstring file_path(safe_convert(path.native_file_string())); + std::wstring file_path(safe_convert(path.external_file_string())); #else - std::string file_path = utf8_native(path.native_file_string()); + std::string file_path = utf8_native(path.external_file_string()); #endif m_file_handle = CreateFile( @@ -173,7 +173,7 @@ namespace libtorrent | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - m_fd = ::open(path.native_file_string().c_str() + m_fd = ::open(path.external_file_string().c_str() , mode, permissions); if (m_fd == -1) diff --git a/src/storage.cpp b/src/storage.cpp index 71e8c39f9..42a95fbd8 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -160,7 +160,7 @@ namespace // First create branch, by calling ourself recursively create_directories_win(ph.branch_path()); // Now that parent's path exists, create the directory - std::wstring wph(safe_convert(ph.native_directory_string())); + std::wstring wph(safe_convert(ph.external_directory_string())); CreateDirectory(wph.c_str(), 0); return true; } @@ -208,7 +208,7 @@ namespace std::time_t last_write_time_win( const fs::path & ph ) { struct _stat path_stat; - std::wstring wph(safe_convert(ph.native_file_string())); + std::wstring wph(safe_convert(ph.external_file_string())); if ( ::_wstat( wph.c_str(), &path_stat ) != 0 ) boost::throw_exception( filesystem_error( "boost::filesystem::last_write_time", @@ -273,9 +273,9 @@ namespace libtorrent for (basic_directory_iterator i(old_path), end; i != end; ++i) { #if BOOST_VERSION < 103600 - recursive_copy(i->path(), new_path / i->leaf(), ec); + recursive_copy(i->path(), new_path / i->path().leaf(), ec); #else - recursive_copy(i->path(), new_path / i->filename(), ec); + recursive_copy(i->path(), new_path / i->path().filename(), ec); #endif if (ec) return; } @@ -392,7 +392,7 @@ namespace libtorrent || (!compact_mode && size < s->first)) { if (error) *error = "filesize mismatch for file '" - + i->path.native_file_string() + + i->path.external_file_string() + "', size: " + boost::lexical_cast(size) + ", expected to be " + boost::lexical_cast(s->first) + " bytes"; @@ -405,7 +405,7 @@ namespace libtorrent (!compact_mode && (time > s->second + 5 * 60) || time < s->second - 1)) { if (error) *error = "timestamp mismatch for file '" - + i->path.native_file_string() + + i->path.external_file_string() + "', modification date: " + boost::lexical_cast(time) + ", expected to have modification date " + boost::lexical_cast(s->second); @@ -832,7 +832,7 @@ namespace libtorrent { if (i->size != fs->first) { - error = "file size for '" + i->path.native_file_string() + error = "file size for '" + i->path.external_file_string() + "' was expected to be " + boost::lexical_cast(i->size) + " bytes"; return false; @@ -858,7 +858,7 @@ namespace libtorrent save_path = complete(save_path); #if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400 - std::wstring wsave_path(safe_convert(save_path.native_file_string())); + std::wstring wsave_path(safe_convert(save_path.external_file_string())); if (!exists_win(save_path)) CreateDirectory(wsave_path.c_str(), 0); else if ((GetFileAttributes(wsave_path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) == 0) diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index bebb51735..8fe17ab1e 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. using boost::filesystem::remove_all; using boost::filesystem::create_directory; using namespace libtorrent; +namespace sf = boost::filesystem; void print_alerts(libtorrent::session& ses, char const* name , bool allow_disconnects, bool allow_no_torrents, bool allow_failed_fastresume) @@ -128,7 +129,7 @@ void start_web_server(int port, bool ssl) std::ofstream f("lighty_config"); f << "server.modules = (\"mod_access\", \"mod_redirect\", \"mod_setenv\")\n" - "server.document-root = \"" << boost::filesystem::initial_path().string() << "\"\n" + "server.document-root = \"" << fs::initial_path().string() << "\"\n" "server.range-requests = \"enable\"\n" "server.port = " << port << "\n" "server.pid-file = \"./lighty" << port << ".pid\"\n" diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 74dec9a43..6e7893cb0 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -544,7 +544,7 @@ int test_main() char* env = std::getenv("TORRENT_TEST_PATHS"); if (env == 0) { - test_paths.push_back(initial_path()); + test_paths.push_back(initial_path()); } else {