Skip to content

Commit 2ef8754

Browse files
committed
Fix package name encoding issues in apt_get_download
Replace direct `apt-get download` with curl approach to handle package names containing special characters. The `apt-get download` command encodes special characters in package names but doesn't decode them when saving files to disk, causing filename issues. This change uses `apt-get --print-uris` to get the download URL, then uses `curl -fLJO` to download with proper filename handling. Signed-off-by: Suraj Deshmukh <suraj.deshmukh@microsoft.com>
1 parent 6fe7592 commit 2ef8754

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

parts/linux/cloud-init/artifacts/cse_helpers.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,24 @@ apt_get_download() {
517517
retries=$1; wait_sleep=$2; shift && shift;
518518
local ret=0
519519
pushd $APT_CACHE_DIR || return 1
520-
for i in $(seq 1 $retries); do
520+
for i in $(seq 1 "$retries"); do
521521
dpkg --configure -a --force-confdef
522522
wait_for_apt_locks
523-
apt-get -o Dpkg::Options::=--force-confold download -y "${@}" && break
524-
if [ $i -eq $retries ]; then ret=1; else sleep $wait_sleep; fi
523+
524+
# Pull the first quoted URL from --print-uris
525+
url="$(apt-get --print-uris -o Dpkg::Options::=--force-confold download -y -- "$@" \
526+
| awk -F"'" 'NR==1 && $2 {print $2}')"
527+
if [ -n "$url" ]; then
528+
# This avoids issues with the naming in the package. `apt-get download`
529+
# encodes the package names with special characters and does not decode
530+
# them when saving to disk, but `curl -J` handles the names correctly.
531+
if curl -fLJO -- "$url"; then ret=0; break; fi
532+
fi
533+
534+
if [ "$i" -eq "$retries" ]; then ret=1; else sleep "$wait_sleep"; fi
525535
done
526536
popd || return 1
527-
return $ret
537+
return "$ret"
528538
}
529539

530540
getCPUArch() {

0 commit comments

Comments
 (0)