fix(setup-aur): self-heal interrupted package transactions
An interrupted pacman -Syu leaves unowned files on disk; every later install then fails with "exists in filesystem" and the whole AUR build cascades into cryptic errors. A failed -Syu is now retried with --overwrite, and all pacman -U installs go through a new pacman_ur() helper that removes only files owned by no package and retries (up to 8 times) instead of dying on stale leftovers.
This commit is contained in:
1 file changed
+45
-5
+45
-5
@@ -184,8 +184,16 @@ pacman-key --populate archlinux 2>/dev/null || true
|
||||
# (ex. gcc-libs → libgcc + libstdc++) sinon makepkg plantera sur
|
||||
# "conflicting files" lors de l'install des dépendances.
|
||||
info "Mise à jour complète du système (peut être long la première fois)…"
|
||||
pacman -Syu --noconfirm \
|
||||
|| warn "pacman -Syu a partiellement échoué — on continue"
|
||||
if ! pacman -Syu --noconfirm; then
|
||||
# État « sale » (upgrade interrompu = fichiers présents mais non possédés par
|
||||
# pacman) : la transaction échoue avec « exists in filesystem ». Ces fichiers
|
||||
# appartiennent AUX paquets à mettre à jour → un --overwrite les réinstalle et
|
||||
# répare l'état. Sans ça, tous les pacman -U suivants (install depuis
|
||||
# local-repo) échouent en cascade avec des erreurs hors-sujet.
|
||||
warn "pacman -Syu a échoué (conflits de fichiers ?) — retry avec --overwrite pour réparer l'état…"
|
||||
pacman -Syu --noconfirm --overwrite='*' \
|
||||
|| warn "pacman -Syu a partiellement échoué — on continue"
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
step "1/4 — Outils de build"
|
||||
@@ -229,6 +237,39 @@ repo_has() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Installe des .pkg (pacman -U) en tolérant les fichiers RÉSIDUELS NON POSSÉDÉS
|
||||
# (« <pkg>: <path> exists in filesystem »). Ces fichiers sont des restes d'un
|
||||
# pacman -Syu interrompu (extraction à moitié faite, DB jamais commitée) : ils
|
||||
# n'appartiennent à AUCUN paquet et le transaction en cours les réécrit de toute
|
||||
# façon → on ne supprime QUE les fichiers sans propriétaire (pacman -Qo vide),
|
||||
# puis on réessaie. Un fichier possédé par un AUTRE paquet reste un vrai conflit
|
||||
# (on ne le touche pas et le pacman -U finit par échouer proprement).
|
||||
pacman_ur() {
|
||||
local i out rc conflicts=() f removed
|
||||
for i in 1 2 3 4 5 6 7 8; do
|
||||
if out="$(pacman -U --noconfirm --needed "$@" 2>&1)"; then
|
||||
return 0
|
||||
fi
|
||||
rc=$?
|
||||
mapfile -t conflicts < <(printf '%s\n' "$out" \
|
||||
| sed -n 's/^[^:]*: \(.*\) exists in filesystem$/\1/p')
|
||||
if [ "${#conflicts[@]}" -eq 0 ]; then
|
||||
printf '%s\n' "$out" >&2
|
||||
return "$rc"
|
||||
fi
|
||||
removed=0
|
||||
for f in "${conflicts[@]}"; do
|
||||
if ! pacman -Qo "$f" >/dev/null 2>&1; then
|
||||
if [ -f "$f" ] || [ -L "$f" ]; then
|
||||
rm -f "$f" && removed=$((removed + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
warn "Fichiers résiduels non possédés supprimés : $removed — nouvel essai ($i/8)…"
|
||||
done
|
||||
error "pacman -U a échoué après 8 essais (conflits de fichiers non résolus)"
|
||||
}
|
||||
|
||||
# Publie les .pkg d'un build vers local-repo en purgeant d'abord les anciennes
|
||||
# versions de CE paquet (+ son sous-paquet -debug). Le « -[0-9] » empêche
|
||||
# « anaconda » d'attraper « anaconda-widgets » / « anaconda-debug ».
|
||||
@@ -254,8 +295,7 @@ build_or_skip() {
|
||||
ver="$(pkgbuild_fullver "$d")"
|
||||
if repo_has "$name" "$ver"; then
|
||||
success "$name $ver déjà construit → saut (install depuis local-repo)"
|
||||
pacman -U --noconfirm --needed "$LOCAL_REPO/$name-$ver-"*.pkg.tar.* \
|
||||
|| error "Install (repo) de $name échouée"
|
||||
pacman_ur "$LOCAL_REPO/$name-$ver-"*.pkg.tar.*
|
||||
return 0
|
||||
fi
|
||||
info "Build $name ${ver:+($ver) }(peut prendre plusieurs minutes)…"
|
||||
@@ -277,7 +317,7 @@ build_or_skip() {
|
||||
| grep -E '\.pkg\.tar\.')
|
||||
for f in "${pkgfiles[@]}"; do [ -e "$f" ] && existing+=("$f"); done
|
||||
[ "${#existing[@]}" -gt 0 ] || error "Aucun paquet produit trouvé pour $name"
|
||||
pacman -U --noconfirm "${existing[@]}" || error "Install de $name échouée"
|
||||
pacman_ur "${existing[@]}"
|
||||
publish_to_repo "$name" "${existing[@]}"
|
||||
success "$name build + install OK"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user