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)
{
boost::filesystem::path p(_path);
// Anything that does not start with `.` is an absolute path.
if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != ".."))
return _path;
boost::filesystem::path result(_reference);
// 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();
// TODO: Handle throw of boost::filesystem::filesystem_error
return boost::filesystem::canonical(
boost::filesystem::path(_path),
boost::filesystem::path(_reference).remove_filename();
).generic_string();
}
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.
// See https://github.com/boostorg/filesystem/issues/176
import ".";
// ----
// ParserError 6275: (////:122-133): Source "/" not found: File not supplied initially.