Skip to content

Commit

Permalink
Add --distclean command
Browse files Browse the repository at this point in the history
Adds a command that removes all files (excluding the birb source code)
from /var/cache/distfiles

Fixes #24
  • Loading branch information
Toasterbirb committed Nov 20, 2023
1 parent 86be7be commit ee3caec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions birb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ print_help()
echo " -i --install [options] PACKAGE(s) install given package(s) to the filesystem"
echo " -u --uninstall PACKAGE(s) uninstall given package(s) from the filesystem"
echo " --depclean find and uninstall orphan packages"
echo " --distclean clear the distcache"
echo " --relink PACKAGE(s) re-create symlinks to the package fakeroots"
echo " -s --search search for packages by name"
echo " -b --browse browse packages and their descriptions with fzf"
Expand Down Expand Up @@ -242,6 +243,27 @@ remove_orphan_dependencies()
{ YOLO=true birb --uninstall $ORPHAN_PACKAGES && echo -e "Orphan removal finished!\nReclaimed storage:\n$RECLAIMED_SPACE"; } || println ERROR "Something went wrong during orphan removal..."
}

# Delete all files in /var/cache/distfiles
# This function will leave the birb source code alone though as a precaution
clear_distcache()
{
root_check

# Check how much space will be reclaimed
du --exclude="birb" -shc "$DISTFILES/"

read -rp "Clean distcache? (Y/n): " AGREE_CLEAN_DISTCACHE
case $AGREE_CLEAN_DISTCACHE in
n|N|no|No)
echo "Cancelled"
exit 1
;;
*) ;;
esac

find "$DISTFILES" -maxdepth 1 -type f -delete && echo "Distcache cleared ヽ(*・ω・)ノ" || echo "Something went wrong (*/ω\)"
}

# A wrapper around wget with some error checking and output formatting
# All files are downloaded to /var/cache/distfiles
#
Expand Down Expand Up @@ -1391,6 +1413,12 @@ while test $# -gt 0; do
exit 0
;;

--distclean)
shift
clear_distcache
exit 0
;;

--download)
shift

Expand Down

0 comments on commit ee3caec

Please sign in to comment.