From 9a78c6dfe1f7e10d33307eab64efece9f3d6d41f Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 13 Oct 2014 17:43:14 -0700 Subject: [PATCH] improve register_datasources + drop filesystem v2 support since v3 is default in boost >= 1.46 --- INSTALL.md | 4 +- include/mapnik/datasource_cache.hpp | 2 +- src/datasource_cache.cpp | 57 ++++++++++++++++++----------- src/font_engine_freetype.cpp | 12 ------ src/fs.cpp | 48 ------------------------ 5 files changed, 38 insertions(+), 85 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 95fe2531a..f2787e671 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -58,11 +58,11 @@ Build system dependencies are: Mapnik Core depends on: * Boost - - >= 1.47 is required. + - >= 1.47 is required and >= 1.56 recommended - These libraries are used: - filesystem - system - - thread (if mapnik threadsafe support is required, default on) + - thread (for python bindings only) - regex (optionally built with icu regex support) - program_options (optionally for mapnik command line programs) * libicuuc >= 4.0 (ideally >= 4.2) - International Components for Unicode diff --git a/include/mapnik/datasource_cache.hpp b/include/mapnik/datasource_cache.hpp index bd646abb8..2a8b75205 100644 --- a/include/mapnik/datasource_cache.hpp +++ b/include/mapnik/datasource_cache.hpp @@ -48,7 +48,7 @@ class MAPNIK_DECL datasource_cache public: std::vector plugin_names(); std::string plugin_directories(); - void register_datasources(std::string const& path); + bool register_datasources(std::string const& path, bool recurse = false); bool register_datasource(std::string const& path); std::shared_ptr create(parameters const& params); private: diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index bc75ed8ab..95c9425b6 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -150,48 +150,61 @@ std::vector datasource_cache::plugin_names() return names; } -void datasource_cache::register_datasources(std::string const& str) +bool datasource_cache::register_datasources(std::string const& dir, bool recurse) { #ifdef MAPNIK_THREADSAFE mapnik::scoped_lock lock(mutex_); #endif - if (!mapnik::util::exists(str)) + if (!mapnik::util::exists(dir)) { - return; + return false; } - plugin_directories_.insert(str); - if (!mapnik::util::is_directory(str)) + plugin_directories_.insert(dir); + if (!mapnik::util::is_directory(dir)) { - register_datasource(str); + return register_datasource(dir); } - else + bool success = false; + try { boost::filesystem::directory_iterator end_itr; #ifdef _WINDOWS - std::wstring wide_dir(mapnik::utf8_to_utf16(str)); + std::wstring wide_dir(mapnik::utf8_to_utf16(dir)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) -#else - for (boost::filesystem::directory_iterator itr(str); itr != end_itr; ++itr ) -#endif { - -#if (BOOST_FILESYSTEM_VERSION == 3) - if (!boost::filesystem::is_directory(*itr) && is_input_plugin(itr->path().filename().string())) -#else // v2 - if (!boost::filesystem::is_directory(*itr) && is_input_plugin(itr->path().leaf())) + std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); +#else + for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) + { + std::string file_name = itr->path().string(); #endif + if (boost::filesystem::is_directory(*itr) && recurse) { -#if (BOOST_FILESYSTEM_VERSION == 3) - if (register_datasource(itr->path().string())) -#else // v2 - if (register_datasource(itr->string())) -#endif + if (register_datasources(file_name, true)) { - registered_ = true; + success = true; + } + } + else + { + std::string base_name = itr->path().filename().string(); + if (!boost::algorithm::starts_with(base_name,".") && + mapnik::util::is_regular_file(file_name) && + is_input_plugin(file_name)) + { + if (register_datasource(file_name)) + { + success = true; + } } } } } + catch (std::exception const& ex) + { + MAPNIK_LOG_ERROR(datasource_cache) << "register_datasources: " << ex.what(); + } + return success; } bool datasource_cache::register_datasource(std::string const& filename) diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index da568f3bb..e89f88e50 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -191,19 +191,11 @@ bool freetype_engine::register_fonts_impl(std::string const& dir, std::wstring wide_dir(mapnik::utf8_to_utf16(dir)); for (boost::filesystem::directory_iterator itr(wide_dir); itr != end_itr; ++itr) { - #if (BOOST_FILESYSTEM_VERSION == 3) std::string file_name = mapnik::utf16_to_utf8(itr->path().wstring()); - #else // v2 - std::string file_name = mapnik::utf16_to_utf8(itr->wstring()); - #endif #else for (boost::filesystem::directory_iterator itr(dir); itr != end_itr; ++itr) { -#if (BOOST_FILESYSTEM_VERSION == 3) std::string file_name = itr->path().string(); -#else // v2 - std::string file_name = itr->string(); -#endif #endif if (boost::filesystem::is_directory(*itr) && recurse) { @@ -214,11 +206,7 @@ bool freetype_engine::register_fonts_impl(std::string const& dir, } else { -#if (BOOST_FILESYSTEM_VERSION == 3) std::string base_name = itr->path().filename().string(); -#else // v2 - std::string base_name = itr->filename(); -#endif if (!boost::algorithm::starts_with(base_name,".") && mapnik::util::is_regular_file(file_name) && is_font_file(file_name)) diff --git a/src/fs.cpp b/src/fs.cpp index bcb109f32..247c4a4d8 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -20,8 +20,6 @@ * *****************************************************************************/ -//#define BOOST_FILESYSTEM_VERSION 2 - // mapnik #include #include @@ -32,40 +30,6 @@ // stl #include -#if (BOOST_FILESYSTEM_VERSION <= 2) - - -namespace boost { -namespace filesystem { -path read_symlink(const path& p) -{ - path symlink_path; - -#ifdef BOOST_POSIX_API - for (std::size_t path_max = 64;; path_max *= 2)// loop 'til buffer is large enough - { - const std::unique_ptr buf(new char[path_max]); - ssize_t result; - if ((result=::readlink(p.string().c_str(), buf.get(), path_max))== -1) - { - throw std::runtime_error("could not read symlink"); - } - else - { - if(result != static_cast(path_max)) - { - symlink_path.assign(buf.get(), buf.get() + result); - break; - } - } - } -#endif - return symlink_path; -} -} -} -#endif - namespace mapnik { namespace util { @@ -130,31 +94,19 @@ namespace util { { absolute_path = boost::filesystem::read_symlink(absolute_path); } -#if (BOOST_FILESYSTEM_VERSION == 3) return boost::filesystem::absolute(absolute_path.parent_path() / filepath).string(); -#else - return boost::filesystem::complete(absolute_path.branch_path() / filepath).normalize().string(); -#endif } std::string make_absolute(std::string const& filepath, std::string const& base) { -#if (BOOST_FILESYSTEM_VERSION == 3) // TODO - normalize is now deprecated, use make_preferred? return boost::filesystem::absolute(boost::filesystem::path(base)/filepath).string(); -#else // v2 - return boost::filesystem::complete(boost::filesystem::path(base)/filepath).normalize().string(); -#endif } std::string dirname(std::string const& filepath) { boost::filesystem::path bp(filepath); -#if (BOOST_FILESYSTEM_VERSION == 3) return bp.parent_path().string(); -#else // v2 - return bp.branch_path().string(); -#endif } } // end namespace util