Skip to content

Commit

Permalink
src/apply.bash: Update pacman database before installing packages
Browse files Browse the repository at this point in the history
On a fresh install it might happen that after priority files including
the pacman config are installed, the pacman database is not up to date.

  : Applying configuration...
  :: Installing priority files...
  ::: Installing /etc/pacman.conf...
  :::: Done.
  ::: Done.
  :: Configuring packages...
  ::: Unpinning 4 unknown packages.
  warning: database file for 'community' does not exist (use '-Sy' to download)
  warning: database file for 'multilib' does not exist (use '-Sy' to download)

This can later result in issues with finding the correct package during
the "Apply packages" step.

  error: target not found: lib32-vulkan-intel
  error: target not found: lib32-vulkan-mesa-layers
  error: target not found: steam
  error: target not found: wine

To avoid this issue ask the user if he wishes to do as pacman suggests
and update the database before "Apply packages". To avoid an
inconsistent state upgrade packages for which database entries were
updated, in other words perform a system upgrade.
  • Loading branch information
AleksanderBobinski committed Sep 27, 2024
1 parent 1195f3a commit b01b05c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 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 ! sudo "$PACMAN" --database --check --check
then
function Details() { Log "The pacman database is out of sync with the configuration, update?" ; }
Confirm Details

LogEnter 'Updating pacman database...\n'
sudo "$PACMAN" --sync --refresh --upgrades
LogLeave
fi

#
# Apply packages
#
Expand Down
49 changes: 36 additions & 13 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 Expand Up @@ -244,19 +262,24 @@ function pacman() {
fi
;;
database)
local package
for package in "${args[@]}"
do
if $opt_asdeps
then
printf orphan > "$test_data_dir"/installed-packages/"$package"/inst_as
elif $opt_asexplicit
then
printf explicit > "$test_data_dir"/installed-packages/"$package"/inst_as
else
FatalError 'Mocked pacman --database without --asdeps/--asexplicit\n'
fi
done
if $opt_db_sync_check
then
exit_code=1
else
local package
for package in "${args[@]}"
do
if $opt_asdeps
then
printf orphan > "$test_data_dir"/installed-packages/"$package"/inst_as
elif $opt_asexplicit
then
printf explicit > "$test_data_dir"/installed-packages/"$package"/inst_as
else
FatalError 'Mocked pacman --database without --asdeps/--asexplicit\n'
fi
done
fi
echo pacman "$@" >> "$test_data_dir"/pacman.log
;;
remove)
Expand Down
2 changes: 2 additions & 0 deletions test/t/t-2_apply-1_packages-1_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
--sync test-package
EOF

Expand Down
2 changes: 2 additions & 0 deletions test/t/t-2_apply-1_packages-2_missing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
--database --asdeps test-package
--remove test-package
EOF
Expand Down
2 changes: 2 additions & 0 deletions test/t/t-2_apply-1_packages-3_unpinned.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
--database --asexplicit test-package
EOF

Expand Down
2 changes: 2 additions & 0 deletions test/t/t-2_apply-1_packages-4_orphan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
--remove test-orphan-package
EOF

Expand Down
5 changes: 4 additions & 1 deletion test/t/t-2_apply-1_packages-5_ignore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ TestPhase_Run #################################################################
AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog < /dev/null
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
EOF

TestDone ######################################################################
2 changes: 2 additions & 0 deletions test/t/t-5_helpers-5_addpackagegroup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ AconfApply

TestPhase_Check ###############################################################
TestExpectPacManLog <<EOF
--database --check --check
--sync --refresh --upgrades
--sync test-package
EOF

Expand Down

0 comments on commit b01b05c

Please sign in to comment.