mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
libsolutil: Use boost canonical for absolute path.
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
parent
44493ad428
commit
f76edbb6d4
@ -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) {
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user