Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3d7aa69

Browse files
committed
extract to function
1 parent e725d92 commit 3d7aa69

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

src/ci/scripts/free-disk-space.sh

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ printDF() {
5454
printSeparationLine "="
5555
}
5656

57-
removeDir() {
58-
dir=${1}
59-
60-
local before
61-
before=$(getAvailableSpace)
62-
63-
sudo rm -rf "$dir" || true
64-
65-
printSavedSpace "$before" "Removed $dir"
66-
}
67-
6857
execAndMeasureSpaceChange() {
6958
local operation=${1} # Function to execute
7059
local title=${2}
@@ -141,39 +130,45 @@ removeAllSnaps() {
141130
sudo snap remove $(snap list | awk '!/^Name|^core|^snapd/ {print $1}')
142131
}
143132

133+
removeUnusedDirectories() {
134+
local dirs_to_remove=(
135+
"/usr/lib/heroku/"
136+
"/usr/local/lib/android"
137+
"/usr/local/lib/node_modules"
138+
"/usr/local/share/chromium"
139+
"/usr/local/share/powershell"
140+
"^/usr/share/az_.*"
141+
"/usr/share/dotnet"
142+
"/usr/share/icons/"
143+
"/usr/share/miniconda/"
144+
"/usr/share/swift"
145+
"$AGENT_TOOLSDIRECTORY"
146+
147+
# Haskell runtime
148+
"/opt/ghc"
149+
"/usr/local/.ghcup"
150+
)
151+
local before
152+
153+
for dir in "${dirs_to_remove[@]}"; do
154+
before=$(getAvailableSpace)
155+
sudo rm -rf "$dir" || true
156+
printSavedSpace "$before" "Removed $dir"
157+
done
158+
}
159+
144160
# Display initial disk space stats
145161

146162
AVAILABLE_INITIAL=$(getAvailableSpace)
147163

148164
printDF "BEFORE CLEAN-UP:"
149165
echo ""
150166

151-
dirs_to_remove=(
152-
"/usr/lib/heroku/"
153-
"/usr/local/lib/android"
154-
"/usr/local/lib/node_modules"
155-
"/usr/local/share/chromium"
156-
"/usr/local/share/powershell"
157-
"^/usr/share/az_.*"
158-
"/usr/share/dotnet"
159-
"/usr/share/icons/"
160-
"/usr/share/miniconda/"
161-
"/usr/share/swift"
162-
"$AGENT_TOOLSDIRECTORY"
163-
164-
# Haskell runtime
165-
"/opt/ghc"
166-
"/usr/local/.ghcup"
167-
)
168-
169-
for dir in "${dirs_to_remove[@]}"; do
170-
removeDir "$dir"
171-
done
167+
removeUnusedDirectories
172168

173169
execAndMeasureSpaceChange removeAllSnaps "Snaps"
174170
execAndMeasureSpaceChange cleanPackages "Unused packages"
175171
execAndMeasureSpaceChange cleanDocker "Docker images"
176-
execAndMeasureSpaceChange cleanSwap "Swap storage"
177172

178173
echo "=> largest directories:"
179174
sudo du --max-depth=7 /* -h | sort -nr | head -1000

0 commit comments

Comments
 (0)