implement and use portable implementation of canonical file paths, see #909, this time against dev branch
This commit is contained in:
parent
ea30005762
commit
7580777e43
@ -35,8 +35,54 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#if BOOST_FILESYSTEM_VERSION < 3
|
#if BOOST_FILESYSTEM_VERSION < 3
|
||||||
#warning Boost Installation with Filesystem3 missing, activating workaround
|
#warning Boost Installation with Filesystem3 missing, activating workaround
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
|
// adapted from: http://stackoverflow.com/questions/1746136/how-do-i-normalize-a-pathname-using-boostfilesystem
|
||||||
|
inline boost::filesystem::path portable_canonical(
|
||||||
|
const boost::filesystem::path & relative_path,
|
||||||
|
const boost::filesystem::path & current_path = boost::filesystem::current_path())
|
||||||
|
{
|
||||||
|
const boost::filesystem::path absolute_path = boost::filesystem::absolute(
|
||||||
|
relative_path,
|
||||||
|
current_path
|
||||||
|
);
|
||||||
|
|
||||||
|
boost::filesystem::path canonical_path;
|
||||||
|
for(
|
||||||
|
boost::filesystem::path::const_iterator path_iterator = absolute_path.begin();
|
||||||
|
path_iterator!=absolute_path.end();
|
||||||
|
++path_iterator
|
||||||
|
) {
|
||||||
|
if( ".." == path_iterator->string() ) {
|
||||||
|
// /a/b/.. is not necessarily /a if b is a symbolic link
|
||||||
|
if( boost::filesystem::is_symlink(canonical_path) ) {
|
||||||
|
canonical_path /= *path_iterator;
|
||||||
|
} else if( ".." == canonical_path.filename() ) {
|
||||||
|
// /a/b/../.. is not /a/b/.. under most circumstances
|
||||||
|
// We can end up with ..s in our result because of symbolic links
|
||||||
|
canonical_path /= *path_iterator;
|
||||||
|
} else {
|
||||||
|
// Otherwise it should be safe to resolve the parent
|
||||||
|
canonical_path = canonical_path.parent_path();
|
||||||
|
}
|
||||||
|
} else if( "." == path_iterator->string() ) {
|
||||||
|
// Ignore
|
||||||
|
} else {
|
||||||
|
// Just cat other path entries
|
||||||
|
canonical_path /= *path_iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOST_ASSERT( canonical_path.is_absolute() );
|
||||||
|
BOOST_ASSERT( boost::filesystem::exists( canonical_path ) );
|
||||||
|
return canonical_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if BOOST_FILESYSTEM_VERSION < 3
|
||||||
|
|
||||||
inline path temp_directory_path() {
|
inline path temp_directory_path() {
|
||||||
char * buffer;
|
char * buffer;
|
||||||
buffer = tmpnam (NULL);
|
buffer = tmpnam (NULL);
|
||||||
@ -48,10 +94,9 @@ inline path unique_path(const path&) {
|
|||||||
return temp_directory_path();
|
return temp_directory_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef BOOST_FILESYSTEM_VERSION
|
#ifndef BOOST_FILESYSTEM_VERSION
|
||||||
#define BOOST_FILESYSTEM_VERSION 3
|
#define BOOST_FILESYSTEM_VERSION 3
|
||||||
|
@ -130,7 +130,8 @@ int main( const int argc, const char * argv[] ) {
|
|||||||
paths_iterator = server_paths.find("fileindex");
|
paths_iterator = server_paths.find("fileindex");
|
||||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||||
const std::string & file_index_file_name = paths_iterator->second.string();
|
const boost::filesystem::path index_file_path_absolute = boost::filesystem::portable_canonical(paths_iterator->second);
|
||||||
|
const std::string & file_index_file_name = index_file_path_absolute.string();
|
||||||
paths_iterator = server_paths.find("nodesdata");
|
paths_iterator = server_paths.find("nodesdata");
|
||||||
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
BOOST_ASSERT(server_paths.end() != paths_iterator);
|
||||||
BOOST_ASSERT(!paths_iterator->second.empty());
|
BOOST_ASSERT(!paths_iterator->second.empty());
|
||||||
|
Loading…
Reference in New Issue
Block a user