diff --git a/docs/releasing.md b/docs/releasing.md index 6d35b6379e..f5cd7460ae 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -200,7 +200,15 @@ Why these formats: `~/.local/share/applications/ai.storyteller.photocraft.desktop` with `Exec` rewritten to the AppImage's path (`TryExec` dropped, the binary isn't on the host PATH) and the hicolor icons beside it, rewriting only when the content changed, and any failure leaves - the launch untouched. `PHOTOCRAFT_NO_DESKTOP_INTEGRATION=1` opts out; to uninstall, `rm + the launch untouched. Launcher refresh uses a hidden generated snapshot to preserve + user edits, comments and deleted keys while updating untouched packaged metadata and + known executable paths. Missing or damaged snapshots use a conservative fallback. + External integration removes a duplicate only when a regular launcher exactly matches + a valid regular snapshot. Symlinked launchers or snapshots (including dangling links) + and special files are left alone during both refresh and deduplication; icons still + install. These checks do not synchronize concurrent changes by other processes. + This overlaps the deduplication protection proposed in #5168 without depending on it. + `PHOTOCRAFT_NO_DESKTOP_INTEGRATION=1` opts out; to uninstall, `rm ~/.local/share/applications/ai.storyteller.photocraft.desktop` and `find ~/.local/share/icons/hicolor -name 'ai.storyteller.photocraft*' -delete`. The script is covered by `packaging/linux/apprun-test.sh` in the packaging-lint workflow. diff --git a/packaging/linux/AppRun b/packaging/linux/AppRun index 852aad4f0d..2308af0136 100755 --- a/packaging/linux/AppRun +++ b/packaging/linux/AppRun @@ -17,7 +17,7 @@ DESK_ID=ai.storyteller.photocraft # A damaged snapshot is not evidence that an absent user key was newly added. # Treat it like a legacy installation and preserve the existing launcher. valid_baseline() { - [ -s "$1" ] || return 1 + [ -f "$1" ] && [ ! -L "$1" ] && [ -s "$1" ] || return 1 awk ' /^\[/ { group = $0; if (group == "[Desktop Entry]") sections++; next } /^[ \t]*($|#)/ { next } @@ -79,10 +79,16 @@ integrate() { fi done fi - if [ "$external" = 1 ]; then + if [ -L "$desktop" ] || [ -L "$baseline" ] || + { [ -e "$desktop" ] && [ ! -f "$desktop" ]; } || + { [ -e "$baseline" ] && [ ! -f "$baseline" ]; }; then + # A link (including a dangling one) or special file is not our installation. + # Leave both launcher and snapshot alone; icons may still be installed below. + : + elif [ "$external" = 1 ]; then # Only a byte-identical, valid generated snapshot proves this is ours to # remove. A customized or legacy launcher belongs to the user. - if valid_baseline "$baseline" && cmp -s "$baseline" "$desktop"; then + if [ -f "$desktop" ] && valid_baseline "$baseline" && cmp -s "$baseline" "$desktop" && [ ! -L "$desktop" ]; then if rm -f "$desktop" 2>/dev/null; then command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$apps" >/dev/null 2>&1 fi diff --git a/packaging/linux/apprun-test.sh b/packaging/linux/apprun-test.sh index 5955550e17..4c4ccfafdd 100755 --- a/packaging/linux/apprun-test.sh +++ b/packaging/linux/apprun-test.sh @@ -28,6 +28,7 @@ APPIMAGE="$TMP/photocraft test.AppImage" # spaces on purpose: Exec must stay quo export APPIMAGE export HOME="$TMP/home" export XDG_DATA_HOME="$HOME/.local/share" +unset DESKTOPINTEGRATION PHOTOCRAFT_NO_DESKTOP_INTEGRATION mkdir -p "$HOME" fail() { @@ -151,6 +152,43 @@ for baseline_kind in valid missing empty; do rm -f "$ext" done +# Linked launchers and snapshots are externally owned, even when their bytes +# match a generated entry. Check both normal refresh and external deduplication. +for integration in normal external; do + for linked in launcher dangling-launcher baseline dangling-baseline; do + rm -rf "$XDG_DATA_HOME" + "$APPDIR/AppRun" >/dev/null + baseline="$XDG_DATA_HOME/applications/.$APP_ID.generated" + target="$TMP/linked-target" + cp "$DESKTOP" "$target" + case "$linked" in + launcher|dangling-launcher) link="$DESKTOP" ;; + baseline|dangling-baseline) link="$baseline" ;; + esac + rm -f "$link" + case "$linked" in dangling-*) rm -f "$target" ;; esac + ln -s "$target" "$link" + [ ! -f "$target" ] || cp "$target" "$TMP/linked-target-before" + # A packaged metadata change would otherwise cause a symlink to be replaced. + template="$APPDIR/usr/share/applications/$APP_ID.desktop" + cp "$template" "$TMP/link-template-before" + printf '\nX-Link-Refresh=changed\n' >>"$template" + if [ "$integration" = external ]; then + DESKTOPINTEGRATION=AppImageLauncher "$APPDIR/AppRun" >/dev/null + else + "$APPDIR/AppRun" >/dev/null + fi + [ -L "$link" ] || fail "$integration replaced or removed $linked" + [ "$(readlink "$link")" = "$target" ] || fail "$integration retargeted $linked" + case "$linked" in + dangling-*) [ ! -e "$target" ] || fail "$integration created dangling target" ;; + *) cmp -s "$target" "$TMP/linked-target-before" || fail "$integration changed linked target" ;; + esac + [ -f "$XDG_DATA_HOME/icons/hicolor/256x256/apps/$APP_ID.png" ] || fail "link preservation skipped icons" + cp "$TMP/link-template-before" "$template" + done +done + # Reset the stub fixture so the duplicate-removal test starts with an untouched entry. rm -rf "$XDG_DATA_HOME" "$APPDIR/AppRun" >/dev/null