From c92c737c2bb696fd12eecb53019fe3da287a1719 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 13 Nov 2025 09:41:02 +0100 Subject: [PATCH] core.func: push changes from upstream Added cleanup_lxc function to manage cache and temporary files for various package managers and programming environments. --- scripts/core/core.func | 51 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/scripts/core/core.func b/scripts/core/core.func index 16b7dec..3255eb0 100644 --- a/scripts/core/core.func +++ b/scripts/core/core.func @@ -368,6 +368,54 @@ run_container_safe() { " || __handle_general_error "lxc-attach to CT $ct" } +cleanup_lxc() { + msg_info "Cleaning up" + + if is_alpine; then + $STD apk cache clean || true + rm -rf /var/cache/apk/* + else + $STD apt -y autoremove || true + $STD apt -y autoclean || true + $STD apt -y clean || true + fi + + # Clear temp artifacts (keep sockets/FIFOs; ignore errors) + find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true + find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true + + # Truncate writable log files silently (permission errors ignored) + if command -v truncate >/dev/null 2>&1; then + find /var/log -type f -writable -print0 2>/dev/null | + xargs -0 -n1 truncate -s 0 2>/dev/null || true + fi + + # Python pip + if command -v pip &>/dev/null; then $STD pip cache purge || true; fi + # Python uv + if command -v uv &>/dev/null; then $STD uv cache clear || true; fi + # Node.js npm + if command -v npm &>/dev/null; then $STD npm cache clean --force || true; fi + # Node.js yarn + if command -v yarn &>/dev/null; then $STD yarn cache clean || true; fi + # Node.js pnpm + if command -v pnpm &>/dev/null; then $STD pnpm store prune || true; fi + # Go + if command -v go &>/dev/null; then $STD go clean -cache -modcache || true; fi + # Rust cargo + if command -v cargo &>/dev/null; then $STD cargo clean || true; fi + # Ruby gem + if command -v gem &>/dev/null; then $STD gem cleanup || true; fi + # Composer (PHP) + if command -v composer &>/dev/null; then $STD composer clear-cache || true; fi + + if command -v journalctl &>/dev/null; then + $STD journalctl --rotate || true + $STD journalctl --vacuum-time=10m || true + fi + msg_ok "Cleaned" +} + check_or_create_swap() { msg_info "Checking for active swap" @@ -407,6 +455,3 @@ check_or_create_swap() { } trap 'stop_spinner' EXIT INT TERM - -# Initialize functions when core.func is sourced -load_functions \ No newline at end of file