libsolutil: Use boost canonical for absolute path.

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Bhargava Shastry 2021-02-19 12:11:23 +01:00
parent 44493ad428
commit f76edbb6d4
2 changed files with 7 additions and 16 deletions

View File

@ -132,22 +132,11 @@ int solidity::util::readStandardInputChar()
string solidity::util::absolutePath(string const& _path, string const& _reference) string solidity::util::absolutePath(string const& _path, string const& _reference)
{ {
boost::filesystem::path p(_path); // TODO: Handle throw of boost::filesystem::filesystem_error
// Anything that does not start with `.` is an absolute path. return boost::filesystem::canonical(
if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != "..")) boost::filesystem::path(_path),
return _path; boost::filesystem::path(_reference).remove_filename();
boost::filesystem::path result(_reference); ).generic_string();
// If filename is "/", then remove_filename() throws.
// See: https://github.com/boostorg/filesystem/issues/176
if (result.filename() != boost::filesystem::path("/"))
result.remove_filename();
for (boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it)
if (*it == "..")
result = result.parent_path();
else if (*it != ".")
result /= *it;
return result.generic_string();
} }
string solidity::util::sanitizePath(string const& _path) { string solidity::util::sanitizePath(string const& _path) {

View File

@ -2,3 +2,5 @@
// This test used to throw due to a bug in boost::filesystem. // This test used to throw due to a bug in boost::filesystem.
// See https://github.com/boostorg/filesystem/issues/176 // See https://github.com/boostorg/filesystem/issues/176
import "."; import ".";
// ----
// ParserError 6275: (////:122-133): Source "/" not found: File not supplied initially.