Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 900228 - Document idempotency requirement for pkg_preinst? (Portage's quickpkg may run pkg_preinst a second time, after already run on live system)
Summary: Document idempotency requirement for pkg_preinst? (Portage's quickpkg may run...
Status: CONFIRMED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: PMS/EAPI (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: PMS/EAPI
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-08 04:21 UTC by Sam James
Modified: 2023-08-05 08:17 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-03-08 04:21:23 UTC
We discussed this in #gentoo-pms the other day but filing a bug so we don't lose track of it, as I don't think we clearly document the requirement (or at least a suggestion if we consider this to be a Portage hack, we can put it in devmanual instead) that pkg_preinst should be idempotent.

In bug 899648, I hit a problem with a quickpkg'd app-editors/emacs because its pkg_preinst adjusts the image on initial merge and doesn't expect to be run again. Running quickpkg then creates a binary package *based on the modified image on the system* and pkg_preinst will be run again when the quickpkg-generated binary package is installed.

It's unclear if pkg_preinst's requirements should be adjusted or if we should just document better (e.g. devmanual, maybe phrasing adjustment in PMS to call out a pitfall) that pkg_preinst should be idempotent.

See also PMS "11.3 The State of the System Between Functions" at https://dev.gentoo.org/~ulm/pms/head/pms.html#section-11.3.

So:
- Should we allow pkg_preinst to be run more than once in PMS?
- Should we document in PMS that pkg_preinst might need special care because of this, and therefore be idempotent?
Comment 1 Ionen Wolkens gentoo-dev 2023-03-08 04:46:17 UTC
fwiw nvidia-drivers modifies a "${ED}"/etc file so that it gets the current system's GID for the video group (replaces @VIDEOGID@)

However I don't want to install that file with @VIDEOGID@ and sed it /after/ in postinst, plus want it to go through etc-update/dispatch-conf rather than modify live system as users could've done a lot with that file

So being idempotent would be rather inconvenient here. For the sake of quickpkg, I can at least ensure it won't fail if ran twice, but the GID won't be updated a 2nd time.
Comment 2 Ionen Wolkens gentoo-dev 2023-03-08 04:50:04 UTC
(In reply to Ionen Wolkens from comment #1)
> So being idempotent would be rather inconvenient here. For the sake of
> quickpkg, I can at least ensure it won't fail if ran twice, but the GID
> won't be updated a 2nd time.
By that bit, it also does another check with a temporary uninstalled file that will be missing from the quickpkg (and then `rm || die` will fail). Albeit I can just skip this check if the file is missing.
Comment 3 Ulrich Müller gentoo-dev 2023-03-08 07:38:21 UTC
I'd rather keep the spec strict (i.e. the package manager must not run a phase twice), and document this in the devmanual instead.

Is there any way to fix quickpkg? Alternatively, indicate in the created binpkg that pkg_preinst and pkg_postinst must not be executed again when installing it?
Comment 4 Ulrich Müller gentoo-dev 2023-03-08 09:32:33 UTC
This also affects call order. PMS says that pkg_preinst must be executed before pkg_postinst, but when installing a quickpackaged binpkg, the effective call order is preinst, postinst, preinst, postinst.