#!/bin/sh # garbage collect a package database # flags to skip phases db=${1:-${ZPMDB:-/var/lib/zpm/local.db}} if [ -z "$db" ]; then echo must specify database file exit 1 fi ZPMDB=$db export ZPMDB # check for incorrect hash file content # remove orphaned elf info # remove failed packages for pkg in $(zpm list -s failed); do zpm log -i -a 'gc removing' -t "$pkg" zpm rmpackage "$pkg" done for pkg in $(zpm list -s dryrun); do zpm log -i -a 'gc removing' -t "$pkg" zpm rmpackage "$pkg" done # remove incomplete packages # remove outdated packages, unless preserved # TODO need 'rstatus' flag # remove removed packages, unless preserved # remove orphaned rows in files table # references in packagefiles, notes, scripts, possibly others zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);' # remove old logs, given by date # remove acked notes # remove install history by date # remove history for removed packages # remove command history by date # compactify the database file osize=$(zpm stat -f '%s' $ZPMDB) zpm log -v -i -a 'gc compacting' -t $ZPMDB zpm shell $ZPMDB vacuum nsize=$(zpm stat -f '%s' $ZPMDB) printf 'original size %s\n' $osize printf 'new size %s\n' $nsize