Skip to content

Commit

Permalink
Run "pkg_admin rebuild-tree" after pkgdb changes.
Browse files Browse the repository at this point in the history
There are a number of known issues with +REQUIRED_BY files getting out
of sync when performing forced upgrades or replacements as pkgin does.
These lead to infamous "Can't open +CONTENTS of..." errors when next
attempting to upgrade, as +REQUIRED_BY files contain entries for
packages that no longer exist.

Attempting to fix pkg_install to ensure correct consistency during
replacements is difficult, and there's no guarantee that the installed
pkg_install tools would have any future fixes, and so a simpler
workaround for pkgin for now is to simply rebuild all the +REQUIRED_BY
files after each upgrade.

With recent proposed changes to pkg_install this operation has been
improved, and so the additional runtime (less than 1 second for most
situations) should not be noticeable for most users.

Resolves errors seen in TritonDataCenter/pkgsrc#158, TritonDataCenter/pkgsrc#190,
TritonDataCenter/pkgsrc#256 and many other ad-hoc reports.
  • Loading branch information
Jonathan Perkin committed Apr 27, 2020
1 parent dde05c8 commit 7b84775
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,17 @@ pkgin_install(char **opkgargs, int do_inst, int upgrade)
rc = EXIT_FAILURE;
}

/*
* Recalculate +REQUIRED_BY entries after all installs have finished,
* as things can get out of sync when using pkg_add -DU, leading to the
* dreaded "Can't open +CONTENTS of depending package..." errors when
* upgrading next time.
*/
open_pi_log();
if (fexec(pkg_admin, "rebuild-tree", NULL) != EXIT_SUCCESS)
rc = EXIT_FAILURE;
close_pi_log();

/* pure install, not called by pkgin_upgrade */
if (!upgrade)
(void)update_db(LOCAL_SUMMARY, pkgargs, 1);
Expand Down Expand Up @@ -766,6 +777,16 @@ pkgin_remove(char **pkgargs)
if (check_yesno(DEFAULT_YES)) {
do_pkg_remove(removehead);

/*
* Recalculate +REQUIRED_BY entries in case anything
* has been unable to update correctly.
*/
open_pi_log();
if (fexec(pkg_admin, "rebuild-tree", NULL)
!= EXIT_SUCCESS)
rc = EXIT_FAILURE;
close_pi_log();

(void)update_db(LOCAL_SUMMARY, NULL, 1);
}
} else
Expand Down

0 comments on commit 7b84775

Please sign in to comment.