From a102c9e883e940e3e85dd3b73bc0157dbe74421d Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 3 Oct 2019 17:02:58 +0200 Subject: [PATCH] Introduce Utility::RealPath() --- lib/base/utility.cpp | 24 ++++++++++++++++++++++++ lib/base/utility.hpp | 2 ++ 2 files changed, 26 insertions(+) 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(); -- 2.50.1