From b5f7a383b2b2b39204e11fb3ba345477ab405b5f Mon Sep 17 00:00:00 2001 From: 0xbbuddha Date: Tue, 23 Sep 2025 21:22:40 +0200 Subject: [PATCH] feat: add cache --list option and refactor cache functions --- arch-shell | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/arch-shell b/arch-shell index 138cb5c..4e27f9d 100755 --- a/arch-shell +++ b/arch-shell @@ -191,6 +191,18 @@ usage_clean() { exit 1 } +usage_cache() { + echo "Usage: $0 clean [options]" + echo "" + echo "Permet de gérer le cache partagé arch-shell." + echo "" + echo "Options:" + echo " --stats Afficher les statistiques du cache" + echo " --list Lister les paquets dans le cache" + echo " --clean Nettoyer le cache" + exit 1 +} + init_shared_cache() { debug_log "Initialisation du cache partagé dans $SHARED_CACHE" mkdir -p "$SHARED_CACHE/pkg" @@ -1233,11 +1245,46 @@ case "$1" in fi ;; cache) + if [ $# -lt 2 ]; then + usage_cache + fi case "${2:-}" in --stats) init_shared_cache show_cache_stats ;; + --list) + init_shared_cache + echo -e "${BLUE}[*] Paquets dans le cache partagé :${NC}" + if [ ! -d "$SHARED_CACHE/pkg" ] || [ -z "$(ls -A "$SHARED_CACHE/pkg" 2>/dev/null)" ]; then + echo -e "${YELLOW}[*] Aucun paquet dans le cache${NC}" + else + total_count=0 + total_size=0 + declare -A seen_packages + + for pkg in "$SHARED_CACHE/pkg"/*.pkg.tar.*; do + [ -f "$pkg" ] || continue + pkg_name=$(basename "$pkg") + + [[ "$pkg_name" == *.sig ]] && continue + + pkg_clean=$(echo "$pkg_name" | sed 's/\.pkg\.tar\..*//') + + [ "${seen_packages[$pkg_clean]:-}" ] && continue + seen_packages[$pkg_clean]=1 + + pkg_size=$(stat -c%s "$pkg" 2>/dev/null || echo "0") + + echo -e " ${GREEN}•${NC} $pkg_clean ($(numfmt --to=iec $pkg_size))" + total_count=$((total_count + 1)) + total_size=$((total_size + pkg_size)) + done + + echo "" + echo -e "${BLUE}[*] Total : ${total_count} paquets ($(numfmt --to=iec $total_size))${NC}" + fi + ;; --clean) init_shared_cache days_old="${3:-30}" @@ -1256,7 +1303,6 @@ case "$1" in update_cache_stats ;; *) - echo "Usage: $0 cache --stats|--clean [jours]" exit 1 ;; esac