]> pd.if.org Git - zpackage/blob - zpm-gc
add passes to zpm-gc
[zpackage] / zpm-gc
1 #!/bin/sh
2
3 # garbage collect a package database
4 # flags to skip phases
5
6 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
7
8 if [ -z "$db" ]; then
9         echo must specify database file
10         exit 1
11 fi
12
13 ZPMDB=$db
14 export ZPMDB
15
16 # check for incorrect hash file content
17
18 # remove orphaned elf info
19
20 # remove failed packages
21 for pkg in $(zpm list -s failed); do
22         zpm log -i -a 'gc removing' -t "$pkg"
23         zpm rmpackage "$pkg"
24 done
25
26 for pkg in $(zpm list -s dryrun); do
27         zpm log -i -a 'gc removing' -t "$pkg"
28         zpm rmpackage "$pkg"
29 done
30
31 # remove incomplete packages
32
33 # remove outdated packages, unless preserved
34 # TODO need 'rstatus' flag
35
36 # remove removed packages, unless preserved
37
38 # remove orphaned rows in files table
39 # references in packagefiles, notes, scripts, possibly others
40
41 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
42
43 # remove old logs, given by date
44
45 # remove acked notes
46
47 # remove install history by date
48
49 # remove history for removed packages
50
51 # remove command history by date
52
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)
58
59 printf 'original size %s\n' $osize
60 printf 'new size %s\n' $nsize