X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-gc;h=06807efa8f1d1b374450644f9dec450511b40302;hb=2eb30b5a4eb5feb15cab31a908686ef4e8d4b1f2;hp=f07cdaffd969d6c6bf4188cd672a123bf7e55be2;hpb=c5ae43ca2ab5b4a323e6154d0e08c629cc5a5e1d;p=zpackage diff --git a/zpm-gc b/zpm-gc index f07cdaf..06807ef 100755 --- a/zpm-gc +++ b/zpm-gc @@ -3,6 +3,45 @@ # garbage collect a package database # flags to skip phases +# -C clear all phases +# -n dry run +# -a all phases +# default is failed packages, orphaned elf, vacuum +# +# only affect files with the status in the list +status= +# phases +# -cC remove command history by date +remove_command_history= +# -dD remove dry run +remove_dry_run=1 +# -eE remove orphaned elf +remove_orphaned_elf=1 +# -fF remove failed +remove_failed=1 +# -hH fix file content hash +fix_hash=0 +# -hH remove install history by date +remove_history= +# -lL remove old logs, given by date +remove_logs= +# -nN remove acked notes +remove_acked_notes=0 +# -oO remove outdated packages, unless preserved +remove_old_packages=0 +# -pP remove history for missing packages +clean_missing_package_history=0 +# -rR remove orphaned rows in files table packagefiles, notes, scripts, ... +remove_orphaned_files=1 +# -hH remove all file content that is not scripts or configs +remove_packagefile_content=1 +remove_script_content=1 +remove_config_content=1 +# -rR remove removed packages, unless preserved +remove_removed_packages=0 +# -vV compactify the database file +vacuum=1 + db=${1:-${ZPMDB:-/var/lib/zpm/local.db}} if [ -z "$db" ]; then @@ -29,24 +68,51 @@ for pkg in $(zpm list -s dryrun); do done # remove incomplete packages +# TODO use temporary gc delete log trigger? +if [ $remove_incomplete_packages -ne 0 ]; then + zpm shell $ZPMDB "delete from packages where hash is null" +fi -# remove outdated packages, unless preserved +# remove old version packages, unless preserved # TODO need 'rstatus' flag +if [ $remove_old_packages -ne 0 ]; then + # TODO check for preserved + # TODO add ability to keep a certain number of back packages + zpm shell $ZPMDB "delete from packages where status = 'updated'" +fi # remove removed packages, unless preserved # remove orphaned rows in files table # references in packagefiles, notes, scripts, possibly others +if [ $remove_orphaned_files -ne 0 ]; then + zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);' +fi + # remove old logs, given by date # remove acked notes +if [ $remove_acked_notes -ne 0 ]; then + zpm shell $ZPMDB 'delete from notes where ack != 0' +fi # remove install history by date -# remove history for removed packages +# remove history for missing packages +if [ $clean_missing_package_history -ne 0 ]; then + +fi # remove command history by date -# compactify the database file +if [ $vacuum -ne 0 ]; then + # 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 +fi