Skip to content

Commit

Permalink
Check whether a modulemd file exists before download/parse
Browse files Browse the repository at this point in the history
There's a modulemd.arch.txt for each archicture the module has been
built for.
If we're, for example, trying to get module info for aarch64
and the modulemd.aarch64.txt doesn't exist, it most likely means
that there's been no aarch64 build.
  • Loading branch information
jpopelka committed Jan 25, 2024
1 parent eabec34 commit e67ae50
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mtps-get-module
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if [ -z "${YUMDNFCMD:-}" ]; then source "$(dirname "${BASH_SOURCE[0]}")/mtps-set

RET_NO_RPMS_IN_BREW=7
RET_NO_RPMS_IN_REPOS=8
RET_NO_MODULE_ARCH=9

builds_from_answer() {
local xml="$1" && shift
Expand Down Expand Up @@ -174,6 +175,17 @@ mk_url_mmd() {
echo "$url"
}

url_exists() {
local url="$1" && shift
response=$(curl --silent --head "$url" | grep HTTP)
if [[ $response != *" 404 "* && $response != *" 403 "* ]]; then
return 0
else
echo "$url does not exist"
return 1
fi
}

download_artifact() {
local url="$1" && shift
local dstdir="$1" && shift
Expand Down Expand Up @@ -453,6 +465,10 @@ if [[ -z "$builds_in_m" ]]; then
fi

mmd_url="$(mk_url_mmd "$m_nvr" "$ARCH")"
if ! url_exists "$mmd_url"; then
echo "$m_nvr has probably not been built for $ARCH"
exit $RET_NO_MODULE_ARCH
fi
mmd_file="$(basename "$mmd_url")"
mmd_dir="$(mktemp --directory)"
download_artifact "$mmd_url" "$mmd_dir"
Expand Down

0 comments on commit e67ae50

Please sign in to comment.