Search code examples
dpkg

How can I tell a debian package to forget about a file (such that the file doesn't get deleted during a purge or remove)?


A debian package I made overwrote files belonging to other packages (using --force-overwrite option). I realized this was bad, but after deleting these files from the package, building and reinstalling, it'll delete those files since it think's my package owns those files and no longer needs them.

I need dpkg to forget my package ever knew about those files, such that I can remove/purge/install and without it ever thinking about those files again.

Note that this package is only meant to be deployed on systems I control, not distributed to clients, so tinkering with already installed packages is acceptable, so long as I can get this back to a non-messed up state.

Couldn't find an answer on stackoverflow or here, appreciate any help or links to similar questions I missed.


Solution

  • Found that dpkg stores a list of each installed package's files here:

    /var/lib/dpkg/info/mydpkg.list
    

    Appears to be a list of every directory and file installed by the package, eg

    /etc/udev
    /etc/udev/rules.d
    /etc/udev/rules.d/95-serial485-pi3.rules
    /etc/udev/rules.d/97-serial485-pi4.rules
    

    Fix: sudo vim /var/lib/dpkg/info/mydpkg.list and delete lines of files I want my package to forget about, therefore not trying to delete when uninstalling (or when installing a new version of the package that doesn't have those files anymore.) Unclear on if it's necessary to delete the lines referencing parent directories (eg /etc/udev and /etc/udev/rules.d above).

    Bonus: I found this by using strace on the command that lists these files, finding out where it gets its info from:

    strace dpkg-query -L mydpkg
    

    Taken from here: https://unix.stackexchange.com/questions/200171/where-does-dpkg-l-gather-its-information