From 78949cf3fd31d8a408e93af7e27bcf26ae7942f4 Mon Sep 17 00:00:00 2001 From: Chen Qi Date: Tue, 2 Nov 2021 17:02:45 +0800 Subject: fetch2: fix downloadfilename issue with premirror The following commit to fix [Yocto #13039] causes regression of the behavior of PREMIRRORS. "bitbake: fetch2: fix premirror URI when downloadfilename defined" Take meta-openembedded/meta-networking/recipes-protocols/freediameter/freediameter_1.4.0.bb as an example. SRC_URI = "\ http://www.freediameter.net/hg/${fd_pkgname}/archive/${PV}.tar.gz;downloadfilename=${fd_pkgname}-${PV}.tar.gz \ ... " With the above commit, it now tries to fetch 1.4.0.tar.gz instead of freeDiameter-1.4.0.tar.gz. This makes https://downloads.yoctoproject.org/mirror/sources not work for freediameter, as it holds freeDiameter-1.4.0.tar.gz. The commit above tries to avoid fetching from invalid url such as: https:///1.4.0.tar.gz/freeDiameter-1.4.0.tar.gz. And its solution is to make basename to be 1.4.0.tar.gz, thus causing the regression. This patch fixes the above regression. For Yocto #13039, it now tries to fetch from url: https:///freeDiameter-1.4.0.tar.gz. Signed-off-by: Chen Qi Signed-off-by: Richard Purdie (cherry picked from commit 96c30007dc0b32eee2b15771daec7948bc9bfd97) Signed-off-by: Anuj Mittal Signed-off-by: Richard Purdie --- lib/bb/fetch2/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py index 259b2637a..8078991d7 100644 --- a/lib/bb/fetch2/__init__.py +++ b/lib/bb/fetch2/__init__.py @@ -466,9 +466,13 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): # Kill parameters, they make no sense for mirror tarballs uri_decoded[5] = {} elif ud.localpath and ud.method.supports_checksum(ud): - basename = os.path.basename(uri_decoded[loc]) - if basename and not result_decoded[loc].endswith(basename): - result_decoded[loc] = os.path.join(result_decoded[loc], basename) + basename = os.path.basename(ud.localpath) + if basename: + uri_basename = os.path.basename(uri_decoded[loc]) + if basename != uri_basename and result_decoded[loc].endswith(uri_basename): + result_decoded[loc] = result_decoded[loc].replace(uri_basename, basename) + elif not result_decoded[loc].endswith(basename): + result_decoded[loc] = os.path.join(result_decoded[loc], basename) else: return None result = encodeurl(result_decoded) -- cgit 1.2.3-korg