From 58e21e876e3b4184f197ed8c8f48a081130ab3a4 Mon Sep 17 00:00:00 2001 From: DomCristaldi Date: Sat, 20 Jul 2024 22:58:03 -0400 Subject: [PATCH] walk up symlink tree "reload_style_on_change" would check if the target file is a symlink, but only resolves the first link. If the symlink is acutally a chain of symlink, such as what happens with NixOS's mkOutOfStoreSymlink, we will not find the actual file style file. Update the symlink resolution logic to walk down the symlink chain until it finds a non-symlink. Also check against a the original filename (which may be a symlink) to guard against infinitely looping on a circular symlink chain. --- src/util/css_reload_helper.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/css_reload_helper.cpp b/src/util/css_reload_helper.cpp index 45fd801a..e440c3c1 100644 --- a/src/util/css_reload_helper.cpp +++ b/src/util/css_reload_helper.cpp @@ -43,8 +43,14 @@ std::string waybar::CssReloadHelper::findPath(const std::string& filename) { } // File monitor does not work with symlinks, so resolve them - if (std::filesystem::is_symlink(result)) { + std::string original = result; + while(std::filesystem::is_symlink(result)) { result = std::filesystem::read_symlink(result); + + // prevent infinite cycle + if (result == original) { + break; + } } return result;