Skip to content

Commit 026dea1

Browse files
committed
feat: Add removalmode input for flexible directory removal options
Allow selection of file removal modes from rmz find rsync rm
1 parent e3692d6 commit 026dea1

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

action.yml

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ branding:
77
color: "green"
88

99
inputs:
10+
removalmode:
11+
# See analysis in https://github.com/SUPERCILEX/fuc/tree/master/comparisons
12+
description: "File removal mode [rmz, find, rsync, rm]"
13+
required: false
14+
default: "rmz"
15+
1016
mandb:
1117
description: "Remove mandb and disable apt triggers"
1218
required: false
@@ -66,19 +72,37 @@ runs:
6672
}
6773
6874
fast_rmdir() {
75+
# See analysis in https://github.com/SUPERCILEX/fuc/tree/master/comparisons
76+
#
6977
if [[ -d "$1" ]] && [[ -n "$1" ]] && [[ ! "$1" = "/" ]] && [[ ! "$1" = "~" ]]; then
7078
echo "Removing directory: $1"
71-
# remove with rmz
72-
sudo rmz -f "$1" || true
73-
# Remove with find
74-
#sudo find "$1" -type f -delete -print | wc -l
75-
#sudo rm -rf "$1"
76-
# Remove with rsync
77-
# https://runcloud.io/blog/delete-directory-linux --> tldr; rsync of an empty directory is often the fastest way to bulk delete files
78-
# Experimentation disproved this assertion that rsync is faster. Intial tests : find=268seconds, with rsync=383seconds
79-
#sudo mkdir -p /tmp/empty
80-
#sudo rsync -a --delete /tmp/empty/ "$1"/
81-
#sudo rm -rf /tmp/empty "$1"
79+
case "${{ inputs.removalmode }}" in
80+
"rmz")
81+
# Remove with rmz (requires separate download step)
82+
sudo rmz -f "$1" || true
83+
;;
84+
"find")
85+
# Remove with find (available by default)
86+
sudo find "$1" -type f -delete -print | wc -l
87+
sudo rm -rf "$1"
88+
;;
89+
"rsync")
90+
# Remove with rsync (availble by default)
91+
# https://runcloud.io/blog/delete-directory-linux --> tldr; rsync of an empty directory is often the fastest way to bulk delete files
92+
# Experimentation disproved this assertion that rsync is faster.
93+
sudo mkdir -p /tmp/empty
94+
sudo rsync -a --delete /tmp/empty/ "$1"/
95+
sudo rm -rf /tmp/empty "$1"
96+
;;
97+
"rm")
98+
# Remove with standard unix command
99+
sudo rm -rf "$1"
100+
;;
101+
"*")
102+
echo "ERROR: Invalid removalmode specified. Valid values are [rmz, find, rsync, rm]"
103+
exit -1
104+
;;
105+
esac
82106
fi
83107
}
84108
@@ -165,7 +189,10 @@ runs:
165189
GLOBAL_START_TIME=$(date +%s)
166190
AVAILABLE_INITIAL=$(getAvailableSpace)
167191
AVAILABLE_ROOT_INITIAL=$(getAvailableSpace '/')
168-
setup_rmz
192+
193+
if [[ ${{ inputs.removalmode }} == 'rmz' ]]; then
194+
setup_rmz
195+
fi
169196
170197
printDF "BEFORE CLEAN-UP:"
171198
echo ""
@@ -358,9 +385,10 @@ runs:
358385
saved_mapping["overall"]="$(formatByteCount $((AVAILABLE_END - AVAILABLE_INITIAL)) )"
359386
360387
# Iterate over keys
361-
echo "TIME_REPORT: ================================================================================"
362-
printf "TIME_REPORT: %15s | %-10s seconds |\n" "subsection" "time"
388+
echo "TIME_REPORT: == ${{ inputs.removalmode }} ===================================================="
389+
printf "TIME_REPORT: %15s | %-10s seconds | %-12s |\n" "subsection" "time" "size"
390+
echo "TIME_REPORT: ============================================================="
363391
for subsection in "${!times_mapping[@]}"; do
364392
printf "TIME_REPORT: %15s | %-10s seconds | %-12s |\n" "${subsection}" "${times_mapping[$subsection]}" "${saved_mapping[$subsection]}"
365393
done
366-
echo "TIME_REPORT: ================================================================================"
394+
echo "TIME_REPORT: == ${{ inputs.removalmode }} ===================================================="

0 commit comments

Comments
 (0)