From f2f54bb7f19a00b8220ad130ff7f2383bae17299 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sat, 1 Dec 2018 01:27:16 +0000 Subject: [PATCH] add more logic to garbage collector --- zpm-gc | 59 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/zpm-gc b/zpm-gc index bc84e34..06807ef 100755 --- a/zpm-gc +++ b/zpm-gc @@ -8,21 +8,39 @@ # -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 -# -pP remove history for removed packages +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}} @@ -50,32 +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 -zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);' +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 -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) +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 + printf 'original size %s\n' $osize + printf 'new size %s\n' $nsize +fi -- 2.40.0