Skip to content
This repository has been archived by the owner on May 31, 2018. It is now read-only.

Commit

Permalink
ensure AUR RPC URI length is less than 8190 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarquis committed Jun 12, 2014
1 parent 148e6d9 commit 8f8350b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pacaur
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,24 @@ getcachedpkg() {
}

downloadjson() {
aururl="https://aur.archlinux.org/rpc.php?type=multiinfo&v=2"
urlencodedpkgs=($(sed 's/+/%2b/g' <<< $@ | sed 's/@/%40/g')) # pkgname consists of alphanum@._+-
urlargs="$(printf "&arg[]=%s" "${urlencodedpkgs[@]}")"
curl -sfg --compressed -C 0 "https://aur.archlinux.org/rpc.php?type=multiinfo$urlargs&v=2" -o "$tmpdir/rpc.json" || note "e" $"Could not connect to the AUR"
# ensure the URI length is less than 8190 bytes (52 for AUR path, 13 reserved)
if [[ "${#urlargs}" -lt 8125 ]]; then
curl -sfg --compressed -C 0 "$aururl$urlargs" -o "$tmpdir/rpc.json" || note "e" $"Could not connect to the AUR"
else
urlpkgs=("$@")
urlencodedpkgs1=($(sed 's/+/%2b/g' <<< ${urlpkgs[@]:0:$((${#urlpkgs[@]}/2))} | sed 's/@/%40/g'))
urlencodedpkgs2=($(sed 's/+/%2b/g' <<< ${urlpkgs[@]:$((${#urlpkgs[@]}/2))} | sed 's/@/%40/g'))
urlargs1="$(printf "&arg[]=%s" "${urlencodedpkgs1[@]}")"
urlargs2="$(printf "&arg[]=%s" "${urlencodedpkgs2[@]}")"
curl -sfg --compressed -C 0 "$aururl$urlargs1" -o "$tmpdir/rpc1.json" "$aururl$urlargs2" -o "$tmpdir/rpc2.json" || note "e" $"Could not connect to the AUR"
# merge json files
json_reformat < "$tmpdir/rpc1.json" | head -n -2 | sed -r 's/}$/},/g' | sed -r "s/\"resultcount\": [0-9]+/\"resultcount\": \"\?\"/g" > "$tmpdir/rpc.json"
json_reformat < "$tmpdir/rpc2.json" | tail -n +6 >> "$tmpdir/rpc.json"
rm -f "$tmpdir/rpc1.json" "$tmpdir/rpc2.json"
fi
}

getjsonvar() {
Expand Down

0 comments on commit 8f8350b

Please sign in to comment.