Upgrading removes the leftover ship and cso skill folders (GST-3999) (#4844)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-26 14:33:22 +00:00
1 parent e6dd567349
commit fd81a04ba7
6 files changed
+329 -17

No files matched your search

+33 -6
View File
@@ -259,8 +259,11 @@ _backup_skill_md() {
_cleanup_skill_entry() {
local entry="$1" skill="${2:-}" whole="${3:-whole}" e dest src
[ -e "$entry" ] || [ -L "$entry" ] || return 0
# Unclaimed dir (no SKILL.md, no marker): nothing of ours to clean.
# Unclaimed dir (no SKILL.md, no marker): only our links can be left in it,
# such as the sections/ an older cleanup stranded (1.104.0.0, GST-3999).
# Those go, and the directory with them when nothing else is left.
if [ -d "$entry" ] && [ ! -L "$entry" ] && [ ! -e "$entry/SKILL.md" ] && [ ! -L "$entry/SKILL.md" ] && [ ! -f "$entry/.gstack-owned" ]; then
if _remove_our_assets "$entry"; then rmdir "$entry" 2>/dev/null || true; fi
return 0
fi
if ! _entry_is_ours "$entry" "$skill"; then
@@ -298,15 +301,39 @@ _cleanup_skill_entry() {
fi
fi
rm -f "$entry/SKILL.md" "$entry/.gstack-owned"
for e in "$entry"/* "$entry"/.[!.]* "$entry"/..?*; do
[ -L "$e" ] || continue
dest="$(_link_target_abs "$e")" || continue
if _target_is_ours "$dest"; then rm -f "$e"; fi
done
if [ -n "$skill" ]; then _remove_our_assets "$entry" "$INSTALL_DIR/$skill" "$RENDER_DIR/$skill" || true; else _remove_our_assets "$entry" || true; fi
rmdir "$entry" 2>/dev/null || echo " cleaned ${entry##*/}/SKILL.md (other files in that directory were left in place)"
fi
fi
}
# _remove_our_assets DIR [SRC_DIR...] — remove the runtime assets gstack put
# beside a SKILL.md: links resolving into gstack, dangling ones from a removed
# skill included, and real files byte-identical to the same path under a
# SRC_DIR (Windows copies). It also looks one level into each real
# subdirectory such as sections/, never through a linked one, and removes a
# subdirectory it empties. The user's own files, links and directories stay,
# an empty one included. Returns 0 only when it removed something.
_remove_our_assets() {
local d="$1" e dest s ours removed=1
shift
for e in "$d"/* "$d"/.[!.]* "$d"/..?* "$d"/*/* "$d"/*/.[!.]* "$d"/*/..?*; do
[ -L "${e%/*}" ] && continue
ours=0
if [ -L "$e" ]; then
dest="$(_link_target_abs "$e")" || continue
if _target_is_ours "$dest"; then ours=1; fi
elif [ -f "$e" ]; then
for s in "$@"; do
if cmp -s "$e" "$s/${e#"$d"/}"; then ours=1; break; fi
done
fi
[ "$ours" -eq 1 ] || continue
rm -f "$e"
removed=0
[ "${e%/*}" = "$d" ] || rmdir "${e%/*}" 2>/dev/null || true
done
return "$removed"
}
# _dir_only_links DIR — deleting DIR whole loses no real data: every entry is
# a symlink or our marker.
_dir_only_links() {