aboutsummaryrefslogtreecommitdiff
path: root/apkg-clean
diff options
context:
space:
mode:
authoremmett1 <me@emmett1.my>2026-06-21 01:10:02 +0800
committeremmett1 <me@emmett1.my>2026-06-21 01:10:02 +0800
commit770256494d4ec89f6a06c970b921a5ed1b2886a0 (patch)
tree3efca10179d9318b6e8e339d3e5dbf8b0dff646c /apkg-clean
parent0656e3219a09b8ddb59db91d339267bdfa435ff9 (diff)
downloadautils-770256494d4ec89f6a06c970b921a5ed1b2886a0.tar.gz
autils-770256494d4ec89f6a06c970b921a5ed1b2886a0.zip
apkg-clean fixedHEAD0.4main
Diffstat (limited to 'apkg-clean')
-rwxr-xr-xapkg-clean160
1 files changed, 99 insertions, 61 deletions
diff --git a/apkg-clean b/apkg-clean
index 5ea20d5..e0a329f 100755
--- a/apkg-clean
+++ b/apkg-clean
@@ -1,83 +1,121 @@
#!/bin/sh
#
-# this script is for cleanup old packages and sources
+# Cleanup old packages and sources
#
# usage:
-# apkg-clean | xargs rm
-#
+# apkg-clean [-p] [-s] | xargs rm
+
+# Given a source entry from an abuild, return the filename that would be stored.
+source_filename() {
+ s=${1%::noextract}
+ case $s in
+ *::*) printf '%s' "${s%%::*}";;
+ *) printf '%s' "${s##*/}";;
+ esac
+}
-scan_pkgs() {
- [ "$APKG_PACKAGE_DIR" ] && allpkg=$(echo $APKG_PACKAGE_DIR/*.spm 2>/dev/null)
- for i in $(apkg -s); do
- . $(apkg -p $i)/abuild 2>/dev/null
- if [ ! "$APKG_PACKAGE_DIR" ]; then
- for p in $(apkg -p $i)/*.spm; do
- [ -f $p ] || continue
- [ "${p##*/}" = "$name#$version-$release.spm" ] && continue
- echo $p
+# Print stale .spm package files (old versions that don't match current name#version-release.spm).
+stale_packages() {
+ if [ "$APKG_PACKAGE_DIR" ]; then
+ # Collect all current .spm names, then check the centralized dir once.
+ keep=""
+ for i in $(apkg -s 2>/dev/null); do
+ dir=$(apkg -p "$i" 2>/dev/null) || continue
+ unset name version release
+ . "$dir/abuild" 2>/dev/null
+ keep="$keep $name#$version-$release.spm"
+ done
+ for f in "$APKG_PACKAGE_DIR"/*.spm; do
+ [ -f "$f" ] || continue
+ case " $keep " in
+ *" ${f##*/} "*) continue;;
+ esac
+ printf '%s\n' "$f"
+ done
+ else
+ for i in $(apkg -s 2>/dev/null); do
+ dir=$(apkg -p "$i" 2>/dev/null) || continue
+ unset name version release
+ . "$dir/abuild" 2>/dev/null
+ current="$name#$version-$release.spm"
+ for f in "$dir"/*.spm; do
+ [ -f "$f" ] || continue
+ [ "${f##*/}" != "$current" ] && printf '%s\n' "$f"
done
- else
- allpkg=$(echo $allpkg | sed "s|$APKG_PACKAGE_DIR/$name#$version-$release.spm||")
- fi
- done
- [ "$APKG_PACKAGE_DIR" ] && echo $allpkg | tr ' ' '\n'
+ done
+ fi
}
-scan_srcs() {
- [ "$APKG_SOURCE_DIR" ] && allsrc=$(echo $APKG_SOURCE_DIR/* 2>/dev/null)
- for i in $(apkg -s); do
- . $(apkg -p $i)/abuild 2>/dev/null
- unset keep
- for s in $source; do
- s=${s%::noextract}
- case $s in
- *::*) keep="$keep ${s%::*}";;
- */*) keep="$keep ${s##*/}";;
- *) [ "$APKG_SOURCE_DIR" ] || keep="$keep $s";;
+# Print stale source files (not referenced by any package's current source variable).
+stale_sources() {
+ if [ "$APKG_SOURCE_DIR" ]; then
+ # Collect all current source filenames across all recipes.
+ keep=""
+ for i in $(apkg -s 2>/dev/null); do
+ dir=$(apkg -p "$i" 2>/dev/null) || continue
+ unset source
+ . "$dir/abuild" 2>/dev/null
+ for s in $source; do
+ keep="$keep $(source_filename "$s")"
+ done
+ done
+
+ for f in "$APKG_SOURCE_DIR"/*; do
+ [ -f "$f" ] || continue
+ case " $keep " in
+ *" ${f##*/} "*) continue;;
esac
+ printf '%s\n' "$f"
done
- if [ ! "$APKG_SOURCE_DIR" ]; then
- (cd $(apkg -p $i)
+ else
+ # Check each recipe directory, filtering out recipe files and current sources.
+ for i in $(apkg -s 2>/dev/null); do
+ dir=$(apkg -p "$i" 2>/dev/null) || continue
+ unset source
+ . "$dir/abuild" 2>/dev/null
+
+ keep=""
+ for s in $source; do
+ keep="$keep $(source_filename "$s")"
+ done
+
+ (cd "$dir" 2>/dev/null || continue
for f in *; do
+ [ -f "$f" ] || continue
case $f in
- abuild|depends|preinstall|postinstall|*.spm) continue;;
+ abuild|depends|preinstall|postinstall|info|\
+ *.spm|.shasum|.files) continue;;
esac
- echo $keep | tr ' ' '\n' | grep -qx $f || echo $PWD/$f
+ case " $keep " in
+ *" $f "*) continue;;
+ esac
+ printf '%s\n' "$PWD/$f"
done
)
- else
- for f in $keep; do
- allsrc=$(echo $allsrc | sed "s|$APKG_SOURCE_DIR/$f||")
- done
- fi
- done
- [ "$APKG_SOURCE_DIR" ] && echo $allsrc | tr ' ' '\n'
+ done
+ fi
}
-print_help() {
- cat <<EOF
+do_pkg=true
+do_src=true
+
+for arg; do
+ case $arg in
+ -p) do_src=false;;
+ -s) do_pkg=false;;
+ -h) cat <<EOF
usage:
- $0 [-p] [-s] | xargs rm -v
-
+ $0 [-p] [-s] | xargs rm -v
+
options:
- -s print sources only
- -p print packages only
-
-EOF
-}
+ -p print packages only
+ -s print sources only
-if [ "$1" ]; then
- while [ "$1" ]; do
- case $1 in
- -p) scan_pkgs;;
- -s) scan_srcs;;
- -h) print_help;;
- esac
- shift
- done
-else
- scan_pkgs
- scan_srcs
-fi
+EOF
+ exit 0;;
+ esac
+done
+$do_pkg && stale_packages
+$do_src && stale_sources
exit 0