Public bug reported:

Hi,

We build a custom kernel from the Ubuntu kernel git sources.  We
intermittently get errors when it comes to downloading dkms source
packages:

II: dkms-build downloading iwlwifi 
(backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb)
II: fetching 
https://launchpad.net/ubuntu/+archive/primary/+files/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
II:   fixing 
https://launchpadlibrarian.net/781266379/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
II:   following 
http://launchpadlibrarian.net/781266379/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
curl: (22) The requested URL returned error: 502
dpkg-deb: error: unexpected end of file in archive magic 
version number in backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
make: *** [debian/rules.d/2-binary-arch.mk:236: 
/build/slowfs/build/ci/git/zynstra/Kernel/kernel-noble/work/ubuntu-bionic/debian/stamps/stamp-install-generic]
 Error 2

Looking at the behaviour of the file-downloader script suggests that
there is a problem if a redirect is encountered:

$ curl --silent --fail --show-error
https://launchpad.net/ubuntu/+archive/primary/+files/backport-iwlwifi-
dkms_11510-0ubuntu1.1_all.deb -o /tmp/file.deb -D /tmp/file.deb.hdr

$ ls -l /tmp/file.deb*
-rw-r--r--@ 1 user  wheel    0 10 Sep 11:04 /tmp/file.deb
-rw-r--r--@ 1 user  wheel  902 10 Sep 11:04 /tmp/file.deb.hdr

If curl then errors when following the Location extracted from the .hdr
file the 0 byte .deb is left.  The later package_present test in
debian/scripts/dkms-build succeeds without falling back to the
alternative download urls.

Either the script should remove the 0 byte .deb if it follows a redirect
or should remove it before the exit 1, e.g.

diff --git a/debian/scripts/file-downloader b/debian/scripts/file-downloader
index 0ebfb4de24194..6a63aad91d626 100755
--- a/debian/scripts/file-downloader
+++ b/debian/scripts/file-downloader
@@ -20,7 +20,7 @@ do

        echo "II: $what $url"

-       curl --silent --fail --show-error "$url" -o "$to" -D "$to.hdr" || exit 1
+       curl --silent --fail --show-error "$url" -o "$to" -D "$to.hdr" || { rm 
-f "$to" ; exit 1 ; }
        redirect=$(awk '/^Location: / 
{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2); print $2;}' "$to.hdr")
        [ -z "$redirect" ] && break
        what='  following'

This is present in at least the ubuntu-noble and ubuntu-resolute trees.

Possibly the "Location:" header match should be made case insenstive:
https://datatracker.ietf.org/doc/html/rfc7230#section-3.2

** Affects: linux (Ubuntu)
     Importance: Undecided
         Status: New

** Description changed:

  Hi,
  
  We build a custom kernel from the Ubuntu kernel git sources.  We
  intermittently get errors when it comes to downloading dkms source
  packages:
  
  II: dkms-build downloading iwlwifi 
(backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb)
  II: fetching 
https://launchpad.net/ubuntu/+archive/primary/+files/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
  II:   fixing 
https://launchpadlibrarian.net/781266379/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
  II:   following 
http://launchpadlibrarian.net/781266379/backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
  curl: (22) The requested URL returned error: 502
  dpkg-deb: error: unexpected end of file in archive magic 
version number in backport-iwlwifi-dkms_11510-0ubuntu1.1_all.deb
  make: *** [debian/rules.d/2-binary-arch.mk:236: 
/build/slowfs/build/ci/git/zynstra/Kernel/kernel-noble/work/ubuntu-bionic/debian/stamps/stamp-install-generic]
 Error 2
  
- 
- Looking at the behaviour of the file-downloader script suggests that there is 
a problem if a redirect is encountered:
+ Looking at the behaviour of the file-downloader script suggests that
+ there is a problem if a redirect is encountered:
  
  $ curl --silent --fail --show-error
  https://launchpad.net/ubuntu/+archive/primary/+files/backport-iwlwifi-
  dkms_11510-0ubuntu1.1_all.deb -o /tmp/file.deb -D /tmp/file.deb.hdr
  
  $ ls -l /tmp/file.deb*
  -rw-r--r--@ 1 user  wheel    0 10 Sep 11:04 /tmp/file.deb
  -rw-r--r--@ 1 user  wheel  902 10 Sep 11:04 /tmp/file.deb.hdr
  
  If curl then errors when following the Location extracted from the .hdr
  file the 0 byte .deb is left.  The later package_present test in
  debian/scripts/dkms-build succeeds without falling back to the
  alternative download urls.
  
  Either the script should remove the 0 byte .deb if it follows a redirect
  or should remove it before the exit 1, e.g.
  
  diff --git a/debian/scripts/file-downloader b/debian/scripts/file-downloader
  index 0ebfb4de24194..6a63aad91d626 100755
  --- a/debian/scripts/file-downloader
  +++ b/debian/scripts/file-downloader
  @@ -20,7 +20,7 @@ do
  
-         echo "II: $what $url"
+         echo "II: $what $url"
  
  -       curl --silent --fail --show-error "$url" -o "$to" -D "$to.hdr" || 
exit 1
  +       curl --silent --fail --show-error "$url" -o "$to" -D "$to.hdr" || { 
rm -f "$to" ; exit 1 ; }
-         redirect=$(awk '/^Location: / 
{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2); print $2;}' "$to.hdr")
-         [ -z "$redirect" ] && break
-         what='  following'
+         redirect=$(awk '/^Location: / 
{gsub(/^[[:space:]]+|[[:space:]]+$/,"",$2); print $2;}' "$to.hdr")
+         [ -z "$redirect" ] && break
+         what='  following'
  
  This is present in at least the ubuntu-noble and ubuntu-resolute trees.
  
- Possibly the "Location:" header match should be made case insenstive: 'awk 
'/^Location: /i ...', 
+ Possibly the "Location:" header match should be made case insenstive:
  https://datatracker.ietf.org/doc/html/rfc7230#section-3.2

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2166965

Title:
  debian/scripts/file-dowloader: error when following redirects

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2166965/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to