3 # garbage collect a package database
9 # default is failed packages, orphaned elf, vacuum
11 # only affect files with the status in the list
14 # -cC remove command history by date
15 remove_command_history=
18 # -eE remove orphaned elf
22 # -hH fix file content hash
24 # -hH remove install history by date
26 # -lL remove old logs, given by date
28 # -nN remove acked notes
30 # -oO remove outdated packages, unless preserved
32 # -pP remove history for missing packages
33 clean_missing_package_history=0
34 # -rR remove orphaned rows in files table packagefiles, notes, scripts, ...
35 remove_orphaned_files=1
36 # -hH remove all file content that is not scripts or configs
37 remove_packagefile_content=1
38 remove_script_content=1
39 remove_config_content=1
40 # -rR remove removed packages, unless preserved
41 remove_removed_packages=0
42 # -vV compactify the database file
45 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
48 echo must specify database file
55 # check for incorrect hash file content
57 # remove orphaned elf info
59 # remove failed packages
60 for pkg in $(zpm list -s failed); do
61 zpm log -i -a 'gc removing' -t "$pkg"
65 for pkg in $(zpm list -s dryrun); do
66 zpm log -i -a 'gc removing' -t "$pkg"
70 # remove incomplete packages
71 # TODO use temporary gc delete log trigger?
72 if [ $remove_incomplete_packages -ne 0 ]; then
73 zpm shell $ZPMDB "delete from packages where hash is null"
76 # remove old version packages, unless preserved
77 # TODO need 'rstatus' flag
78 if [ $remove_old_packages -ne 0 ]; then
79 # TODO check for preserved
80 # TODO add ability to keep a certain number of back packages
81 zpm shell $ZPMDB "delete from packages where status = 'updated'"
84 # remove removed packages, unless preserved
86 # remove orphaned rows in files table
87 # references in packagefiles, notes, scripts, possibly others
89 if [ $remove_orphaned_files -ne 0 ]; then
90 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
93 # remove old logs, given by date
96 if [ $remove_acked_notes -ne 0 ]; then
97 zpm shell $ZPMDB 'delete from notes where ack != 0'
100 # remove install history by date
102 # remove history for missing packages
103 if [ $clean_missing_package_history -ne 0 ]; then
107 # remove command history by date
109 if [ $vacuum -ne 0 ]; then
110 # compactify the database file
111 osize=$(zpm stat -f '%s' $ZPMDB)
112 zpm log -v -i -a 'gc compacting' -t $ZPMDB
113 zpm shell $ZPMDB vacuum
114 nsize=$(zpm stat -f '%s' $ZPMDB)
116 printf 'original size %s\n' $osize
117 printf 'new size %s\n' $nsize