Skip to content

Commit

Permalink
Merge pull request #204 from AleksanderBobinski/bugfix/stale_database
Browse files Browse the repository at this point in the history
src/apply.bash: Update pacman database before installing packages
  • Loading branch information
CyberShadow authored Oct 23, 2024
2 parents 1195f3a + 5cb934c commit 788860a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/apply.bash
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ function AconfApply() {

LogLeave # Installing priority files

if LC_ALL=C "$PACMAN" 2>&1 | grep --extended-regexp --only-matching 'database file for [a-z]+ does not exist'
then
Log 'The pacman local package database is internally inconsistent. Perform a full refresh and system upgrade now?\n'
Confirm ''

LogEnter 'Performing a full refresh and system upgrade...\n'
sudo "$PACMAN" --sync --refresh --sysupgrade
LogLeave
fi

#
# Apply packages
#
Expand Down
18 changes: 18 additions & 0 deletions test/t/mocks/pacman
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function pacman() {
local opt_groups=0
local opt_asdeps=false
local opt_asexplicit=false
local opt_refresh=false
local opt_upgrades=false
local opt_db_check=false
local opt_db_sync_check=false

local arg
for arg in "$@"
Expand Down Expand Up @@ -64,6 +68,20 @@ function pacman() {
--asexplicit)
opt_asexplicit=true
;;
--refresh)
opt_refresh=true
;;
--upgrades)
opt_upgrades=true
;;
--check)
if $opt_db_check
then
opt_db_sync_check=true
else
opt_db_check=true
fi
;;
-*)
FatalError 'Unknown mocked pacman switch %s\n' "$(Color Y "$arg")"
;;
Expand Down
21 changes: 21 additions & 0 deletions test/t/t-2_apply-1_missing_pacman_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
source ./lib.bash

TestIntegrationOnly

# Test recovery from missing pacman databases.

TestPhase_Setup ###############################################################
command sudo rm -rf /var/lib/pacman/sync
TestCreatePackage test-package native
TestAddConfig AddPackage test-package

TestPhase_Run #################################################################
AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--sync test-package
EOF

TestDone ######################################################################

0 comments on commit 788860a

Please sign in to comment.