1

I'm trying to understand how the creation of packages (rpm, deb, dpkg) work and what the architecture supports and doesn't.

Right now I struggle figuring out what happens when the installation or upgrade of a package fails at different points of the process -ie, error on a scriptlet, not enough disk space (is this checked before starting?)-.

From my current understanding, there's no automatic rollback to a previous working version if there was any. So my question would be, how do packages deal with this scenarios? Aren't scriptlets used at all to backup files and restore them post transaction if some error occurred? (I coudln't find examples so far)

Thank you.

1
  • 1
    See Trunks and Trees. I attempted to write that answer without regard to a specific package manager. Most if not all package managers work in the way @Stephen Kitt has described, with checks between each "stage" of maintenance.
    – eyoung100
    Commented Feb 28 at 20:11

1 Answer 1

0

For Debian (and typically, derivatives), this is described in the Debian Policy chapter on maintainer scripts and the corresponding flowcharts. Errors are handled in combination by dpkg (the tool which handles package extraction etc.) and maintainer scripts.

When upgrading a package:

  1. the existing package’s pre-removal script is called
  2. the new package’s pre-installation script is called
  3. the new package’s files are unpacked
  4. the existing package’s post-removal script is called
  5. the existing package’s files are removed
  6. the new package’s post-installation script is called

At any point, errors are handled, and various maintainer scripts are invoked with “undo” parameters to revert the changes made in previous steps. Ultimately, the package can end up in one of the following states:

  • fully installed in the new version (when everything goes well)
  • fully installed in the existing version (when something fails but all the changes could be backed out)
  • unpacked, needing configuration
  • failed, needing re-installation

For many packages, the default handling is sufficient, and no help from maintainer scripts is required. Other packages are much more complex, e.g. those with databases and schema changes between versions (see the slapd maintainer scripts for example); in some cases they won’t actually handle aborted upgrades themselves, and will instead leave a backup of the existing state and ask the administrator to sort the situation out.

2
  • Do you reckon it's reasonable for maintainer scripts to do backups of files and to try restore them if the installation fails?
    – jrs
    Commented Mar 4 at 9:46
  • Yes, if those files are changed during upgrades and aren’t handled by existing processes (such as the package manager’s upgrade handling). Commented Mar 4 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .