mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(linux): preserve linked AppImage launchers and snapshots
Follow up on the overlap with #5168 without integrating its branch. Keep links and special files intact during refresh and deduplication. Add eight linked-path regressions and document snapshot ownership. The full AppRun harness passes; the test-only patch fails before the fix. AI-assisted with OpenAI Codex for FredApps.
This commit is contained in:
1 parent
bb6005a3cf
commit
a4baa306a8
3 files changed
+56
-4
No files matched your search
+9
-1
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user