Comment 17 for bug 1960582

Revision history for this message
Chengen Du (chengendu) wrote :

[Impact]
Some unexpected files exist in the /var/lib/dpkg folder,
which can cause the dpkg postinst script to throw an exception even though the dpkg package has already been upgraded.

[Fix]
Several similar problems have been reported by different users, but the files that caused the error are not always the same.
For further information, please see the following links:

https://www.reddit.com/r/homelab/comments/vf52d4/i_get_the_following_error_when_i_excute_any_apt/
https://stackoverflow.com/questions/72448922/dpkg-fails-on-ubuntu-server-22-04-lts
https://stackoverflow.com/questions/72581436/configuring-dpkg-fails-with-error-package-dpkg-is-not-configured-yet

The error is caused by the postinst step during installation of the new version.
The "head" command is used to check the file content in the debian/dpkg.post fixup_misplaced_alternatives function, which will throw an error if the file is a directory.
Upstream fixes this issue by the commit 940f86c37f9f (debian: Ignore directories for the alternatives state fixup).
The new approach will skip files whose type is not a regular file.

[Test Plan]
1. Create a symbolic link in the /var/lib/dpkg folder
   ln -s /var/lib/dpkg /var/lib/dpkg/dpkg
2. Install the dpkg package using the dpkg command:
   root@jammy:~/dpkg# dpkg -i dpkg_1.21.1ubuntu2.1_amd64.deb
   (Reading database ... 162774 files and directories currently installed.)
   Preparing to unpack dpkg_1.21.1ubuntu2.1_amd64.deb ...
   Unpacking dpkg (1.21.1ubuntu2.1) over (1.21.1ubuntu2.1) ...
   Setting up dpkg (1.21.1ubuntu2.1) ...
   head: error reading 'dpkg': Is a directory
   dpkg: error processing package dpkg (--install):
    installed dpkg package post-installation script subprocess returned error exit status 1
   Processing triggers for man-db (2.10.2-1) ...
   Errors were encountered while processing:
    dpkg

[Where problems could occur]
The intended purpose of the fixup is not to throw an error if the file is a directory but to move the alternative state files back into the alternative state directory.
The fixup has also been removed by the upstream commit 03abb4932e9c (debian: Remove no longer needed alternatives fixup from postint).
Keeping the unrecognized files untouched will be the same approach as upstream currently handles.
The regression can be considered low because there is no behavior change compared to the current upstream version.