improve register_datasources + drop filesystem v2 support since v3 is default in boost >= 1.46
This commit is contained in:
parent
66ce021ad5
commit
9a78c6dfe1
5 changed files with 38 additions and 85 deletions
|
@ -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
|
||||
|
|
|
@ -48,7 +48,7 @@ class MAPNIK_DECL datasource_cache
|
|||
public:
|
||||
std::vector<std::string> 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<datasource> create(parameters const& params);
|
||||
private:
|
||||
|
|
|
@ -150,48 +150,61 @@ std::vector<std::string> 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)
|
||||
|
|
|
@ -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))
|
||||
|
|
48
src/fs.cpp
48
src/fs.cpp
|
@ -20,8 +20,6 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//#define BOOST_FILESYSTEM_VERSION 2
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/utils.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
@ -32,40 +30,6 @@
|
|||
// stl
|
||||
#include <stdexcept>
|
||||
|
||||
#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<char[]> 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<ssize_t>(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
|
||||
|
|
Loading…
Reference in a new issue