Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
84c70ba767 | ||
|
ca0bc3ce5b | ||
|
a45c4055fe |
1 changed files with 32 additions and 10 deletions
42
src/fs.cpp
42
src/fs.cpp
|
@ -28,9 +28,14 @@
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
#include <boost/filesystem/convenience.hpp>
|
#include <boost/filesystem/convenience.hpp>
|
||||||
|
#ifdef _WINDOWS
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#if (BOOST_FILESYSTEM_VERSION <= 2)
|
#if (BOOST_FILESYSTEM_VERSION <= 2)
|
||||||
|
|
||||||
|
@ -108,13 +113,13 @@ namespace util {
|
||||||
|
|
||||||
bool is_relative(std::string const& filepath)
|
bool is_relative(std::string const& filepath)
|
||||||
{
|
{
|
||||||
|
if (filepath.empty()) return true;
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
boost::filesystem::path child_path(mapnik::utf8_to_utf16(filepath));
|
static const boost::regex expression("^[a-zA-Z]:");
|
||||||
|
return (filepath[0] != '\\') && (filepath[0] != '/') && boost::regex_search(filepath,expression);
|
||||||
#else
|
#else
|
||||||
boost::filesystem::path child_path(filepath);
|
return (filepath[0] != '/');
|
||||||
#endif
|
#endif
|
||||||
return (! child_path.has_root_directory() && ! child_path.has_root_name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,12 +144,29 @@ namespace util {
|
||||||
|
|
||||||
std::string make_absolute(std::string const& filepath, std::string const& base)
|
std::string make_absolute(std::string const& filepath, std::string const& base)
|
||||||
{
|
{
|
||||||
#if (BOOST_FILESYSTEM_VERSION == 3)
|
// http://insanecoding.blogspot.com/2007/11/directory-safety-when-working-with.html
|
||||||
// TODO - normalize is now deprecated, use make_preferred?
|
char * _base = realpath(base.c_str(),NULL);
|
||||||
return boost::filesystem::absolute(boost::filesystem::path(base)/filepath).string();
|
if (_base != nullptr) {
|
||||||
#else // v2
|
std::string absolute(_base);
|
||||||
return boost::filesystem::complete(boost::filesystem::path(base)/filepath).normalize().string();
|
free(_base);
|
||||||
#endif
|
absolute += "/" + filepath;
|
||||||
|
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)
|
std::string dirname(std::string const& filepath)
|
||||||
|
|
Loading…
Reference in a new issue