pmb.helpers.repo.download: proper error for 404 (MR 2462)

Flush the progress bar displayed by the function before logging a
warning message for 404 not found responses from the server. Without
flushing, this message gets lost.

In addition to the warning, display a NOTE and ERROR at the end to
explain what went wrong:

  [20:16:50] Update package index for x86_64 (4 file(s))
  [20:16:51] WARNING: file not found: http://mirror.postmarketos.org/postmarketos_get_404_test/edge/main/x86_64/APKINDEX.tar.gz
  [20:16:51] NOTE: check the [mirrors] section in 'pmbootstrap config'
  [20:16:51] ERROR: getting APKINDEX from binary package mirror failed!

Without handling this properly, pmbootstrap would fail slightly later
with a much less useful error:

  [15:14:28] ERROR: expected str, bytes or os.PathLike object, not NoneType

Fixes: pmbootstrap issue 2424
This commit is contained in:
Oliver Smith 2024-10-27 20:19:47 +01:00
parent 3ead8f8859
commit 7269d05b20
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 13 additions and 2 deletions

View file

@ -10,6 +10,7 @@ See also:
import os
import hashlib
from pmb.helpers.exceptions import NonBugError
from pmb.core.context import get_context
from pmb.core.arch import Arch
from pmb.core.pkgrepo import pkgrepo_names
@ -209,7 +210,10 @@ def update(arch: Arch | None = None, force=False, existing_only=False):
# Download and move to right location
for i, (url, target) in enumerate(outdated.items()):
pmb.helpers.cli.progress_print(i / len(outdated))
temp = pmb.helpers.http.download(url, "APKINDEX", False, logging.DEBUG, True)
temp = pmb.helpers.http.download(url, "APKINDEX", False, logging.DEBUG, True, True)
if not temp:
logging.info("NOTE: check the [mirrors] section in 'pmbootstrap config'")
raise NonBugError("getting APKINDEX from binary package mirror failed!")
target_folder = os.path.dirname(target)
if not os.path.exists(target_folder):
pmb.helpers.run.root(["mkdir", "-p", target_folder])