3 # garbage collect a package database
6 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
9 echo must specify database file
16 # check for incorrect hash file content
18 # remove orphaned elf info
20 # remove failed packages
21 for pkg in $(zpm list -s failed); do
22 zpm log -i -a 'gc removing' -t "$pkg"
26 for pkg in $(zpm list -s dryrun); do
27 zpm log -i -a 'gc removing' -t "$pkg"
31 # remove incomplete packages
33 # remove outdated packages, unless preserved
34 # TODO need 'rstatus' flag
36 # remove removed packages, unless preserved
38 # remove orphaned rows in files table
39 # references in packagefiles, notes, scripts, possibly others
41 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
43 # remove old logs, given by date
47 # remove install history by date
49 # remove history for removed packages
51 # remove command history by date
53 # compactify the database file
54 osize=$(zpm stat -f '%s' $ZPMDB)
55 zpm log -v -i -a 'gc compacting' -t $ZPMDB
56 zpm shell $ZPMDB vacuum
57 nsize=$(zpm stat -f '%s' $ZPMDB)
59 printf 'original size %s\n' $osize
60 printf 'new size %s\n' $nsize