Arch pkg cache: remove partial download-* files before pacman -Sc

pacman -Sc errors with 'could not open file .../download-XXXX: Error
reading fd 7' on leftover incomplete downloads. Find and remove them
(with confirm) first, then run paccache/pacman -Sc cleanly.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-22 00:45:17 +07:00
co-authored by Claude
parent 171e5dc9c0
commit 3dbed651e5
+11
View File
@@ -255,6 +255,17 @@ step_pkg_cache() {
arch) arch)
local d="/var/cache/pacman/pkg" local d="/var/cache/pacman/pkg"
[ -d "$d" ] && sudo du -sh "$d" [ -d "$d" ] && sudo du -sh "$d"
# Xóa file download tạm (incomplete) — pacman -Sc báo lỗi fd 7 với chúng.
local partial pcount
partial=$(sudo find "$d" -maxdepth 1 -type f -name 'download-*' 2>/dev/null)
if [ -n "$partial" ]; then
pcount=$(printf '%s\n' "$partial" | grep -c .)
echo " ${C_WARN}✗ ${pcount} file download tạm (incomplete).${C_RESET}"
if confirm_yn "Xóa file download-* tạm?"; then
printf '%s\n' "$partial" | xargs sudo rm -f --
echo "${C_OK} ✓ Đã xóa file tạm.${C_RESET}"
fi
fi
if command -v paccache >/dev/null 2>&1; then if command -v paccache >/dev/null 2>&1; then
sudo paccache -dk2 # dry-run xem trước sudo paccache -dk2 # dry-run xem trước
if confirm_yn "paccache -rk2 (giữ 2 bản)?"; then if confirm_yn "paccache -rk2 (giữ 2 bản)?"; then