Skip to content

Commit

Permalink
Fix DNF5 repoquery
Browse files Browse the repository at this point in the history
related: QubesOS/qubes-core-admin-client#308
(cherry picked from commit e0cecd0)
  • Loading branch information
alimirjamali authored and marmarek committed Nov 5, 2024
1 parent debf2ad commit ef6bfcc
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions qubes-rpc/qvm-template-repo-query
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,38 @@ touch -r "$hashfile" "$repodir/template.repo"
RET=0

if [ "$1" = "query" ]; then
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
if $DNF5; then
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{repoid}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|\n' "$SPEC"
else
dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{repoid}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC"
fi
RET="$?"
elif [ "$1" = "download" ]; then
# Download/retry algorithm: take mirrors in random order. In this order,
# try to download from the first one - if download failed but anything was
# downloaded - retry from the same one. If download failed and nothing was
# downloaded, go to the next one. The intention is to retry on interrupted
# connection, but skip mirrors that are not synchronized yet.
urls="$(dnf downloadurl "${OPTS[@]}" --url --all-mirrors "$SPEC" | shuf)"
readarray -t urls <<<"$urls"
declare -a urls=()
if $DNF5 && dnf download --help | grep -q allmirrors; then
# The smartest case. DNF5 on Fedora 41 with --allmirrors patch
space_separated_urls="$(dnf download "${OPTS[@]}" --url --allmirrors "$SPEC")"
readarray -d ' ' -t urls <<<"$space_separated_urls"
urls=( $(shuf -e "${urls[@]}") )
elif $DNF5; then
# The middle case. DNF5 on Fedora 41 before --allmirror patch
# TODO: Phase out after DNF5 --allmirrors patch is released
url="$(dnf download "${OPTS[@]}" --url "$SPEC")"
urls=("$url")
else
# The old DNF4 on Fedora 40 and other old templates
# use vendored 'downloadurl' dnf-plugin (fork of 'download' plugin),
# to print all mirrors.
# TODO: Phase out after DNF4 is EOL
OPTS+=("--setopt=pluginpath=/usr/lib/qubes/dnf-plugins")
urls="$(dnf downloadurl "${OPTS[@]}" --url --all-mirrors "$SPEC" | shuf)"
readarray -t urls <<<"$urls"
fi
downloaded=0
status_file="$repodir/download-status.tmp"
for url in "${urls[@]}"; do
Expand Down

0 comments on commit ef6bfcc

Please sign in to comment.