Skip to content

Commit b77d7d4

Browse files
fix: clear cache algo
1 parent 58ac6df commit b77d7d4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

udroid/src/udroid.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ TITLE() { echo -e "\e[100m${*}\e[0m";:;}
2929
# Fetch distro data from the internet and save it to RTCACHE
3030
# @param mode [online/offline] - online mode will fetch data from the internet, offline will use the cached data
3131
# @return distro_data [string] - path to the downloaded data
32-
3332
fetch_distro_data() {
3433

3534
# default to online mode
@@ -89,7 +88,7 @@ fetch_distro_data() {
8988
ask() {
9089
local msg=$*
9190

92-
echo -ne "$msg\t[Y/N]: "
91+
echo -ne "$msg\t[y/n]: "
9392
read -r choice
9493

9594
case $choice in
@@ -255,7 +254,7 @@ install() {
255254

256255
login() {
257256
# [ yoinked & modified ]
258-
# Most of the code is taken from proot-utils.sh
257+
# Most of the code is taken from proot-disro
259258
# PERMALINK : https://github.com/termux/proot-distro/blob/fcee91ca6c7632c09898c9d0a680c8ff72c3357f/proot-distro.sh#L933
260259
#
261260
# @termux/proot-distro (C) GNU V3 License
@@ -980,22 +979,27 @@ _reset() {
980979
TITLE "[TODO] RESET"
981980
}
982981

982+
# clear_cache() => clears filesystem cache
983+
# check for file in cache
984+
# if found calclulate size
985+
# ask for confirmation
986+
# if confirmed, remove files
983987
clear_cache() {
984988
TITLE "> CLEAR CACHE"
985989
cache_size=$(du -sh -d 0 $DLCACHE | awk '{print $1}')
986990

987-
# check if cache is empty
988-
if [[ $cache_size == "0" ]]; then
989-
GWARN "cache is already empty"
991+
# check for files
992+
if [[ -z $(ls -A $DLCACHE) ]]; then
993+
GWARN " ? cache is empty"
990994
exit 0
991995
fi
992996

993997
# ask for confirmation
994-
if ask "Are you sure you want to clear cache?"; then
995-
rm -rf $DLCACHE/*
998+
if ask "Do you want to clear cache?"; then
999+
rm -rvf $DLCACHE/* >> $LOGFILE
9961000
echo "$cache_size cache cleared"
9971001
else
998-
GWARN "cache not cleared"
1002+
GWARN " ? cache not cleared"
9991003
fi
10001004
}
10011005
####################

0 commit comments

Comments
 (0)