From: Alexander A. Klimov Date: Thu, 3 Oct 2019 15:02:58 +0000 (+0200) Subject: Introduce Utility::RealPath() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a102c9e883e940e3e85dd3b73bc0157dbe74421d;p=icinga2 Introduce Utility::RealPath() --- diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 1add7616c..da0224226 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -1901,3 +1901,27 @@ bool Utility::ComparePasswords(const String& enteredPassword, const String& actu return result; } + +String Utility::RealPath(const String& path) +{ + namespace fs = boost::filesystem; + + fs::path current (path.Begin(), path.End()); + + for (int i = 0; i < 40; ++i) { + boost::system::error_code ec; + auto next (fs::read_symlink(current, ec)); + + if (ec) { + break; + } + + if (!next.is_absolute()) { + next = current.parent_path() / next; + } + + current = next; + } + + return current.c_str(); +} diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index 4505dc918..3cf63f564 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -144,6 +144,8 @@ public: static void IncrementTime(double); #endif /* I2_DEBUG */ + static String RealPath(const String& path); + private: Utility();