]> granicus.if.org Git - icinga2/commitdiff
Introduce Utility::RealPath()
authorAlexander A. Klimov <grandmaster@al2klimov.de>
Thu, 3 Oct 2019 15:02:58 +0000 (17:02 +0200)
committerAlexander A. Klimov <grandmaster@al2klimov.de>
Thu, 3 Oct 2019 15:02:58 +0000 (17:02 +0200)
lib/base/utility.cpp
lib/base/utility.hpp

index 1add7616c6109ef03d12af0bc288865dc28f10cb..da0224226e157b03af4b6fb88b726e42666da0ad 100644 (file)
@@ -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();
+}
index 4505dc918a5dca8d32395cc88c576322cd6206b2..3cf63f564f665bb687202b44168d45d548528e41 100644 (file)
@@ -144,6 +144,8 @@ public:
        static void IncrementTime(double);
 #endif /* I2_DEBUG */
 
+       static String RealPath(const String& path);
+
 private:
        Utility();