fix: only convert config symlinks when modification is needed. fix #2299

This commit is contained in:
Lemmy
2026-03-25 17:18:54 -04:00
parent e29a71e9a4
commit 2623f081d6
2 changed files with 24 additions and 11 deletions
+18 -6
View File
@@ -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."
+6 -5
View File
@@ -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"):