dpkg ↔ maintainer scripts: ensuring idempotent writes during retry
0 reputation · 27 Jan 2026, 18:19 UTC
dpkg ↔ maintainer scripts: ensuring idempotent writes during retry
The goal is to understand how Debian’s package manager, dpkg, interacts with package maintainer scripts when an installation or configuration is interrupted and later retried. dpkg uses lock files under /var/lib/dpkg to serialize operations, but it does not automatically roll back a partially executed postinst or prerm script. The status file (/var/lib/dpkg/status) records a package as half-installed or config-files, which triggers re‑execution of certain scripts on a subsequent dpkg --configure -a or reinstall.
Because Debian policy recommends that maintainer scripts be idempotent, the actual retry safety depends on the individual package implementation. The question is whether dpkg provides any mechanisms or conventions that can be relied upon to prevent duplicate filesystem writes when a script is re‑run.
- What hooks or flags does
dpkgexpose to detect that a maintainer script has already performed its actions? - Can a maintainer script reliably detect a partial run and skip idempotent operations, or is the responsibility entirely on the package maintainer?
- Does the Debian policy or
dpkgdocumentation specify any recommended patterns for ensuring safe retries of non‑idempotent scripts?