Skip to content

Commit 4bbb290

Browse files
anoopcs9phlogistonjohn
authored andcommitted
images/server: Simplify loop to detect repo file collision
There's a possibility of an infinite loop if the hashed repo name for the url happens to exist at the destination. Therefore replace `while` loop with basic `if` condition and skip the url altogether when hashed repo name exists. Signed-off-by: Anoop C S <[email protected]>
1 parent d9f7d4d commit 4bbb290

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

images/server/install-packages.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ get_custom_repos() {
2020
for url in $urls; do
2121
fname="$(basename "$url")"
2222
dest="/etc/yum.repos.d/${fname}"
23-
while [ -e "$dest" ]; do
23+
if [ -e "$dest" ]; then
2424
u="$(echo "${url}" | sha256sum | head -c12)"
2525
if [ -z "$u" ]; then
2626
echo "failed to uniquify repo file name"
2727
exit 2
2828
fi
2929
dest="/etc/yum.repos.d/${u}-${fname}"
30-
done
30+
if [ -e "$dest" ]; then
31+
continue
32+
fi
33+
fi
3134
curl -L "$url" -o "$dest"
3235
done
3336
fi

0 commit comments

Comments
 (0)