diff options
author | Damian Pietruchowski <d.pietruchow@samsung.com> | 2017-03-03 13:10:57 +0100 |
---|---|---|
committer | Bartlomiej <b.kunikowski@partner.samsung.com> | 2017-03-10 08:49:37 +0100 |
commit | adc349c7d998d95ece0ef1b73ee209e8bb06384d (patch) | |
tree | 88fb62800ad203cd90e64206d7a629fb21b0d8a4 | |
parent | 7457e82c6eb7e8f4439105cc354977a2b8192572 (diff) | |
download | app-installers-adc349c7d998d95ece0ef1b73ee209e8bb06384d.tar.gz app-installers-adc349c7d998d95ece0ef1b73ee209e8bb06384d.tar.bz2 app-installers-adc349c7d998d95ece0ef1b73ee209e8bb06384d.zip |
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 <d.pietruchow@samsung.com>
-rw-r--r-- | src/common/utils/file_util.cc | 8 |
1 files 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, |