]> pd.if.org Git - zpackage/blob - zpm-gc
update for repository installing support
[zpackage] / zpm-gc
1 #!/bin/sh
2
3 # garbage collect a package database
4 # flags to skip phases
5
6 # -C clear all phases
7 # -n dry run
8 # -a all phases
9 # default is failed packages, orphaned elf, vacuum
10
11 # phases
12 # -cC remove command history by date
13 # -dD remove dry run
14 # -eE remove orphaned elf
15 # -fF remove failed
16 # -hH fix file content hash
17 # -hH remove install history by date
18 # -lL remove old logs, given by date
19 # -nN remove acked notes
20 # -oO remove outdated packages, unless preserved
21 # -pP remove history for removed packages
22 # -rR remove orphaned rows in files table packagefiles, notes, scripts, ...
23 # -rR remove removed packages, unless preserved
24 # -vV compactify the database file
25
26 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
27
28 if [ -z "$db" ]; then
29         echo must specify database file
30         exit 1
31 fi
32
33 ZPMDB=$db
34 export ZPMDB
35
36 # check for incorrect hash file content
37
38 # remove orphaned elf info
39
40 # remove failed packages
41 for pkg in $(zpm list -s failed); do
42         zpm log -i -a 'gc removing' -t "$pkg"
43         zpm rmpackage "$pkg"
44 done
45
46 for pkg in $(zpm list -s dryrun); do
47         zpm log -i -a 'gc removing' -t "$pkg"
48         zpm rmpackage "$pkg"
49 done
50
51 # remove incomplete packages
52
53 # remove outdated packages, unless preserved
54 # TODO need 'rstatus' flag
55
56 # remove removed packages, unless preserved
57
58 # remove orphaned rows in files table
59 # references in packagefiles, notes, scripts, possibly others
60
61 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
62
63 # remove old logs, given by date
64
65 # remove acked notes
66
67 # remove install history by date
68
69 # remove history for removed packages
70
71 # remove command history by date
72
73 # compactify the database file
74 osize=$(zpm stat -f '%s' $ZPMDB)
75 zpm log -v -i -a 'gc compacting' -t $ZPMDB
76 zpm shell $ZPMDB vacuum
77 nsize=$(zpm stat -f '%s' $ZPMDB)
78
79 printf 'original size %s\n' $osize
80 printf 'new size %s\n' $nsize