From 2623f081d6bd77d75346964306cc570e0d50c7e7 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Wed, 25 Mar 2026 17:18:54 -0400 Subject: [PATCH] fix: only convert config symlinks when modification is needed. fix #2299 --- Scripts/bash/template-apply.sh | 24 +++++++++++++++++------ Scripts/python/src/theming/gtk-refresh.py | 11 ++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Scripts/bash/template-apply.sh b/Scripts/bash/template-apply.sh index a0a837a69..b33a74a9f 100755 --- a/Scripts/bash/template-apply.sh +++ b/Scripts/bash/template-apply.sh @@ -335,16 +335,16 @@ hyprland) echo -e "\n$INCLUDE_LINE\n" >"$CONFIG_FILE" echo "Created new config file with noctalia theme." else - if [ -L "$CONFIG_FILE" ] && [ ! -w "$CONFIG_FILE" ]; then - echo "Detected read-only symlink, converting to local file..." - cp --remove-destination "$(readlink -f "$CONFIG_FILE")" "$CONFIG_FILE" - chmod +w "$CONFIG_FILE" - fi - # Check if noctalia theme source already exists (flexible matching) if grep -qE 'source\s*=\s*.*noctalia.*\.conf' "$CONFIG_FILE"; then echo "Theme already included, skipping modification." else + # Only convert symlink when we actually need to write + if [ -L "$CONFIG_FILE" ] && [ ! -w "$CONFIG_FILE" ]; then + echo "Detected read-only symlink, converting to local file..." + cp --remove-destination "$(readlink -f "$CONFIG_FILE")" "$CONFIG_FILE" + chmod +w "$CONFIG_FILE" + fi # Add the include line to the end of the file echo -e "\n$INCLUDE_LINE\n" >>"$CONFIG_FILE" echo "✅ Added noctalia theme include to config." @@ -372,6 +372,12 @@ sway) if grep -qE 'include\s+.*noctalia' "$CONFIG_FILE"; then echo "Theme already included, skipping modification." else + # Only convert symlink when we actually need to write + if [ -L "$CONFIG_FILE" ] && [ ! -w "$CONFIG_FILE" ]; then + echo "Detected read-only symlink, converting to local file..." + cp --remove-destination "$(readlink -f "$CONFIG_FILE")" "$CONFIG_FILE" + chmod +w "$CONFIG_FILE" + fi # Add the include line to the end of the file echo -e "\n$INCLUDE_LINE\n" >>"$CONFIG_FILE" echo "✅ Added noctalia theme include to config." @@ -399,6 +405,12 @@ scroll) if grep -qE 'include\s+.*noctalia' "$CONFIG_FILE"; then echo "Theme already included, skipping modification." else + # Only convert symlink when we actually need to write + if [ -L "$CONFIG_FILE" ] && [ ! -w "$CONFIG_FILE" ]; then + echo "Detected read-only symlink, converting to local file..." + cp --remove-destination "$(readlink -f "$CONFIG_FILE")" "$CONFIG_FILE" + chmod +w "$CONFIG_FILE" + fi # Add the include line to the end of the file echo -e "\n$INCLUDE_LINE\n" >>"$CONFIG_FILE" echo "Added noctalia theme include to config." diff --git a/Scripts/python/src/theming/gtk-refresh.py b/Scripts/python/src/theming/gtk-refresh.py index 551929803..3a59b611e 100644 --- a/Scripts/python/src/theming/gtk-refresh.py +++ b/Scripts/python/src/theming/gtk-refresh.py @@ -53,15 +53,16 @@ def ensure_gtk_css_import(gtk_css: Path, colors_file: Path, label: str) -> bool: print(f"Error: {label} noctalia.css not found at {colors_file}", file=sys.stderr) return False - # If gtk.css is a symlink, replace it with a regular file - if gtk_css.is_symlink(): - gtk_css.unlink() - - if gtk_css.exists(): + if gtk_css.exists() or gtk_css.is_symlink(): content = gtk_css.read_text() # Already has the import (flexible: allow optional whitespace / different quoting) if "noctalia.css" in content and "@import" in content: return True + # Need to modify — convert symlink to regular file first + if gtk_css.is_symlink(): + resolved = gtk_css.resolve() + gtk_css.unlink() + gtk_css.write_text(resolved.read_text()) # Append import to the end new_content = content.rstrip() if new_content and not new_content.endswith("\n"):