From b01b05cb9053c5c29f893b69e99da390465dd568 Mon Sep 17 00:00:00 2001 From: Aleksander Bobinski Date: Wed, 11 Sep 2024 23:21:43 +0200 Subject: [PATCH] src/apply.bash: Update pacman database before installing packages 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. --- src/apply.bash | 10 +++++ test/t/mocks/pacman | 49 +++++++++++++++++------ test/t/t-2_apply-1_packages-1_new.sh | 2 + test/t/t-2_apply-1_packages-2_missing.sh | 2 + test/t/t-2_apply-1_packages-3_unpinned.sh | 2 + test/t/t-2_apply-1_packages-4_orphan.sh | 2 + test/t/t-2_apply-1_packages-5_ignore.sh | 5 ++- test/t/t-5_helpers-5_addpackagegroup.sh | 2 + 8 files changed, 60 insertions(+), 14 deletions(-) diff --git a/src/apply.bash b/src/apply.bash index f2716a0f..5e7141e3 100644 --- a/src/apply.bash +++ b/src/apply.bash @@ -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 # diff --git a/test/t/mocks/pacman b/test/t/mocks/pacman index 90f7fc17..594a98ff 100755 --- a/test/t/mocks/pacman +++ b/test/t/mocks/pacman @@ -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 "$@" @@ -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")" ;; @@ -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) diff --git a/test/t/t-2_apply-1_packages-1_new.sh b/test/t/t-2_apply-1_packages-1_new.sh index 58cc7720..8f18ff19 100755 --- a/test/t/t-2_apply-1_packages-1_new.sh +++ b/test/t/t-2_apply-1_packages-1_new.sh @@ -12,6 +12,8 @@ AconfApply TestPhase_Check ############################################################### TestExpectPacManLog <