try realpath instead of boost::filesystem for making paths absolute
This commit is contained in:
parent
0a192a5260
commit
a45c4055fe
2 changed files with 31 additions and 3 deletions
28
src/fs.cpp
28
src/fs.cpp
|
@ -31,6 +31,8 @@
|
|||
|
||||
// stl
|
||||
#include <stdexcept>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#if (BOOST_FILESYSTEM_VERSION <= 2)
|
||||
|
||||
|
@ -139,12 +141,38 @@ namespace util {
|
|||
|
||||
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
|
||||
*/
|
||||
// http://insanecoding.blogspot.com/2007/11/directory-safety-when-working-with.html
|
||||
char * _base = realpath(base.c_str(),NULL);
|
||||
if (_base != nullptr) {
|
||||
std::string absolute(_base);
|
||||
free(_base);
|
||||
absolute += "/" + filepath;
|
||||
std::clog << "abs " << absolute << "\n";
|
||||
return absolute;
|
||||
/*
|
||||
char * res = realpath(absolute.c_str(),NULL);
|
||||
if (res == nullptr) // get here for files that do not exist like ../[this].png
|
||||
{
|
||||
return absolute;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string result(res);
|
||||
std::clog << "res " << result << "\n";
|
||||
free(res);
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
|
||||
std::string dirname(std::string const& filepath)
|
||||
|
|
|
@ -1572,10 +1572,10 @@ std::string map_parser::ensure_relative_to_xml(boost::optional<std::string> cons
|
|||
if (!xml_base_path_.empty())
|
||||
{
|
||||
std::string starting_path = *opt_path;
|
||||
if (mapnik::util::is_relative(starting_path))
|
||||
{
|
||||
//if (mapnik::util::is_relative(starting_path))
|
||||
//{
|
||||
return mapnik::util::make_absolute(starting_path,xml_base_path_);
|
||||
}
|
||||
//}
|
||||
}
|
||||
return *opt_path;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue