Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/apply.bash: Update pacman database before installing packages #204

Merged

Conversation

AleksanderBobinski
Copy link
Contributor

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 do as pacman suggests and update the database before "Apply packages"

Please let me know if I missed something.

@CyberShadow
Copy link
Owner

Hi, unfortunately I don't think this is desired in all circumstances. I think it might also be potentially dangerous, as a database sync must always be followed by a full system upgrade - otherwise, installing a package would result in a partial upgrade.

Could we detect that the databases are missing? In which case, we could do a pacman -Syu in this case, guarded by a Confirm.

@AleksanderBobinski
Copy link
Contributor Author

Good catch. I didn't think about partial upgrades. Allow me to throw some code at you and please let me know if this is the right direction.

src/apply.bash Outdated
@@ -212,6 +212,16 @@ function AconfApply() {

LogLeave # Installing priority files

if ! sudo "$PACMAN" --database --check --check
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that the check (--database --check --check) and the cure (--sync --refresh --upgrades) are checking for / curing the same thing. For example, on my system, this check complains about some missing dependencies, which doesn't seem to be related to the matter at hand, and I don't think would require --refresh to fix.

Perhaps a single --check would do the job? But, if it would be good if we had some way that we could be certain that the check will be positive only in the situations where the fix will do what is needed.

done
if $opt_db_sync_check
then
exit_code=1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is very helpful. The database files missing is an extraordinary circumstance, which I think should have one test dedicated to it, rather than a situation encountered in every test.

In this case, an integration test (which deletes the database files) would probably be the most helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tips on how to create such an integration test? I've been staring at the tests for a while but it's not exactly clear to me how to achieve the removal of a pacman db in the test container.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps take t-2_apply-1_packages-1_new.sh as a base and add TestIntegrationOnly at the top + command sudo rm -rf /var/lib/pacman/sync at the end of the TestPhase_Setup section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem to work, thanks!

src/apply.bash Outdated
@@ -212,6 +212,16 @@ function AconfApply() {

LogLeave # Installing priority files

if ! sudo "$PACMAN" --database --check --check
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check takes a couple seconds for me, even with one --check. It does seem to be more involved than what we need, which is to check that the database files are present. If there's no better way to check for that situation, then probably it should be in a LogEnter / LogLeave block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've poked around and I could grep for something like "database file for 'community' does not exist" since it's printed even when just invoking pacman with no args. What do you think?

[testme@64d38ef3aa04 aconfmgr]$ pacman
warning: database file for 'community' does not exist (use '-Sy' to download)
warning: database file for 'multilib' does not exist (use '-Sy' to download)
error: no operation specified (use -h for help)
[testme@64d38ef3aa04 aconfmgr]$ echo $?
1
[testme@64d38ef3aa04 aconfmgr]$ sudo pacman --database
warning: database file for 'community' does not exist (use '-Sy' to download)
warning: database file for 'multilib' does not exist (use '-Sy' to download)
[testme@64d38ef3aa04 aconfmgr]$ echo $?
0

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no cleaner solution then I guess that would work. Just have to make sure to run it with LC_ALL=C.

src/apply.bash Outdated
@@ -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?" ; }
Copy link
Owner

@CyberShadow CyberShadow Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function Details() { Log "The pacman database is out of sync with the configuration, update?" ; }
function Details() { Log "The pacman local package database is internally inconsistent. Perform a full refresh and system upgrade now?\n" ; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/apply.bash Outdated
function Details() { Log "The pacman database is out of sync with the configuration, update?" ; }
Confirm Details

LogEnter 'Updating pacman database...\n'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LogEnter 'Updating pacman database...\n'
LogEnter 'Performing a full refresh and system upgrade...\n'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/apply.bash Outdated
Confirm Details

LogEnter 'Updating pacman database...\n'
sudo "$PACMAN" --sync --refresh --upgrades
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be --sysupgrade not --upgrades (see CI failure).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - done

Copy link
Owner

@CyberShadow CyberShadow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise!

src/apply.bash Outdated
Comment on lines 217 to 218
function Details() { Log "The pacman local package database is internally inconsistent. Perform a full refresh and system upgrade now?\n" ; }
Confirm Details
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to be a little less confusing, as the user doesn't know what they're agreeing to unless they ask for details:

Suggested change
function Details() { Log "The pacman local package database is internally inconsistent. Perform a full refresh and system upgrade now?\n" ; }
Confirm Details
Log 'The pacman local package database is internally inconsistent. Perform a full refresh and system upgrade now?\n'
Confirm ''

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've added "resolves #33" into the commit message too.

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.

Resolves CyberShadow#33
@CyberShadow CyberShadow merged commit 788860a into CyberShadow:master Oct 23, 2024
7 checks passed
@AleksanderBobinski
Copy link
Contributor Author

Cool! Thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants