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 <d.pietruchow@samsung.com>
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,