From adc349c7d998d95ece0ef1b73ee209e8bb06384d Mon Sep 17 00:00:00 2001 From: Damian Pietruchowski Date: Fri, 3 Mar 2017 13:10:57 +0100 Subject: Change MakeRelativePath() implementation Sometimes current_path(), which is default argument of absolute, throws exception, that directory doesn't exist. This implementation don't require the existence of directories. Change-Id: I0eea7febb6c8acc263f639cda2bcd2b58e0a9f67 Signed-off-by: Damian Pietruchowski --- src/common/utils/file_util.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/utils/file_util.cc b/src/common/utils/file_util.cc index 599d66ad..004df245 100644 --- a/src/common/utils/file_util.cc +++ b/src/common/utils/file_util.cc @@ -593,9 +593,11 @@ bool HasDirectoryClimbing(const boost::filesystem::path& path) { boost::filesystem::path MakeRelativePath(const boost::filesystem::path& input, const boost::filesystem::path& base) { - bf::path input_absolute = bf::absolute(input); - bf::path base_absolute = bf::absolute(base); - return input_absolute.string().substr(base_absolute.string().length() + 1); + if (input.string().find(base.string()) == std::string::npos) { + LOG(ERROR) << base.string() << " is not base path for " << input.string(); + return input; + } + return input.string().substr(base.string().length() + 1); } bool IsSubDir(const boost::filesystem::path& path, -- cgit v1.2.3