Skip to content

Commit dca58f0

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 dca58f0

2 files changed

Lines changed: 17 additions & 5 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() {

parts/linux/cloud-init/artifacts/ubuntu/cse_install_ubuntu.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ downloadPkgFromVersion() {
193193
downloadDir="${3:-"/opt/${packageName}/downloads"}"
194194
mkdir -p ${downloadDir}
195195
apt_get_download 20 30 ${packageName}=${packageVersion} || exit $ERR_APT_INSTALL_TIMEOUT
196-
cp -al ${APT_CACHE_DIR}${packageName}_${packageVersion}* ${downloadDir}/ || exit $ERR_APT_INSTALL_TIMEOUT
196+
# Strip epoch (e.g., 1:4.4.1-1 -> 4.4.1-1)
197+
version_no_epoch="${packageVersion#*:}"
198+
cp -al "${APT_CACHE_DIR}/${packageName}_${version_no_epoch}"* "${downloadDir}/" || exit $ERR_APT_INSTALL_TIMEOUT
197199
echo "Succeeded to download ${packageName} version ${packageVersion}"
198200
}
199201

0 commit comments

Comments
 (0)