Skip to contentSkip to conversation

fetch2: fix downloadfilename issue with premirror

PATCH Superseded Chen Qi 4 participants 5 messages Oct 15, 2021 – Oct 18, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chen Qi

author
#0 lore raw

PATCH 1/1 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://<some_mirror>/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://<some_mirror>/freeDiameter-1.4.0.tar.gz.

---
 lib/bb/fetch2/__init__.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
lib/bb/fetch2/__init__.py +7 -3
index 666cc1306..000b49a50 100644
@@ -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)
Signature · 1 line
2.33.0
#1 lore raw
Quoted 39 lines · Chen Qi

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://<some_mirror>/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://<some_mirror>/freeDiameter-1.4.0.tar.gz.

---
 lib/bb/fetch2/__init__.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
lib/bb/fetch2/__init__.py +0 -3
index 666cc1306..000b49a50 100644
@@ -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)

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 478

Quoted 10 lines
lib/bb/fetch2/__init__.py +7 -0
+                    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)

I've been meaning to reply to this thread as the regression wasn't good. We need to be able to use DL_DIR as a mirror.

Could we add another test case for this case so that this doesn't regress again please?

Cheers,

Richard

#2 lore raw
Quoted 42 lines · Richard Purdie
Quoted 41 lines · Chen Qi

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://<some_mirror>/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://<some_mirror>/freeDiameter-1.4.0.tar.gz.

---
 lib/bb/fetch2/__init__.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
lib/bb/fetch2/__init__.py +2 -3
index 666cc1306..000b49a50 100644
@@ -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:
Quoted 9 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 478

Quoted 8 lines
lib/bb/fetch2/__init__.py +5 -0
+                    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)

Hi Richard and Chen,

Quoted 2 lines

I've been meaning to reply to this thread as the regression wasn't good. We need to be able to use DL_DIR as a mirror.

It's my understanding that DL_DIR is always the last mirror attempted if downloading the artifact from a SRC_URI, MIRRORS and PREMIRRORS fails. In my testing, this still works.

What we're saying is that we want to be able to copy or use an exiting DL_DIR as a PREMIRROR.

If this is the use case then, yes, this is a regression but I'm just a little confused because I always think of a mirror as just being an alternate site where the artifact defined in the SRC_URI can be found.

Once that artifact is found and downloadfilename is defined it should save the artifact using the name defined in downloadfilename.

My apologies for not understanding that downloadfilename also needs to be tried when attempting to download from a premirror. I was going by this definition:

https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#var-SRC_URI

Signature · 1 line
  - Scott
#3 lore raw
Quoted 80 lines

-----Original Message-----
From: [email protected] <bitbake- [email protected]> On Behalf Of Scott Weaver
Sent: den 15 oktober 2021 15:08
To: Richard Purdie <[email protected]>
Cc: Chen Qi <[email protected]>; [email protected]
Subject: Re: [bitbake-devel][PATCH] fetch2: fix downloadfilename issue with premirror

Quoted 7 lines · Richard Purdie
Quoted 6 lines · Chen Qi

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

Quoted 3 lines
Quoted 3 lines

as an example.
SRC_URI = "\

http://www.freediameter.net/hg/${fd_pkgname}/archive/${PV}.tar.gz;download
filename=${fd_pkgname}-${PV}.tar.gz \

Quoted 4 lines
Quoted 4 lines
    ...

"
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

Quoted 5 lines
Quoted 5 lines

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://<some_mirror>/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

Quoted 10 lines
Quoted 10 lines

regression.

This patch fixes the above regression. For Yocto #13039, it now tries to fetch from url: https://<some_mirror>/freeDiameter-1.4.0.tar.gz.

---
 lib/bb/fetch2/__init__.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Quoted 5 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace,

Quoted 5 lines
lib/bb/fetch2/__init__.py +0 -0
index 666cc1306..000b49a50 100644
@@ -466,9 +466,13 @@ def uri_replace(ud, uri_find, uri_replace,

replacements, d, mirrortarball=None):

Quoted 1 line

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 466

Quoted 1 line
lib/bb/fetch2/__init__.py +0 -0
                     # Kill parameters, they make no sense for mirror

tarballs

Quoted 2 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 468

Quoted 2 lines
lib/bb/fetch2/__init__.py +0 -0
                     uri_decoded[5] = {}
                 elif ud.localpath and

ud.method.supports_checksum(ud):

Quoted 2 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 470

Quoted 2 lines
lib/bb/fetch2/__init__.py +0 -2
-                    basename = os.path.basename(uri_decoded[loc])
-                if basename and not

result_decoded[loc].endswith(basename):

Quoted 1 line

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 471

Quoted 1 line
lib/bb/fetch2/__init__.py +0 -1
-                    result_decoded[loc] =

os.path.join(result_decoded[loc], basename)

Quoted 4 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):

Quoted 4 lines
lib/bb/fetch2/__init__.py +4 -0
+                    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):

Quoted 1 line

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 473

Quoted 1 line
lib/bb/fetch2/__init__.py +1 -0
+                        result_decoded[loc] =

result_decoded[loc].replace(uri_basename, basename)

Quoted 2 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, · line 475

Quoted 2 lines
lib/bb/fetch2/__init__.py +2 -0
+                    elif not result_decoded[loc].endswith(basename):
+                        result_decoded[loc] =

os.path.join(result_decoded[loc], basename)

Quoted 4 lines

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 478

Quoted 3 lines
lib/bb/fetch2/__init__.py +0 -0
         else:
             return None
     result = encodeurl(result_decoded)

Hi Richard and Chen,

Quoted 1 line

I've been meaning to reply to this thread as the regression wasn't good.

We need

Quoted 8 lines
Quoted 1 line

to be able to use DL_DIR as a mirror.

It's my understanding that DL_DIR is always the last mirror attempted if downloading the artifact from a SRC_URI, MIRRORS and PREMIRRORS fails. In my testing, this still works.

What we're saying is that we want to be able to copy or use an exiting DL_DIR as a PREMIRROR.

This is basically what the (relatively new) mirror mode of the archiver.bbclass does.

Quoted 11 lines

If this is the use case then, yes, this is a regression but I'm just a little confused because I always think of a mirror as just being an alternate site where the artifact defined in the SRC_URI can be found.

Once that artifact is found and downloadfilename is defined it should save the artifact using the name defined in downloadfilename.

My apologies for not understanding that downloadfilename also needs to be tried when attempting to download from a premirror. I was going by this definition:

Quoted 5 lines

https://www.yoctoproject.org/docs/latest/mega-manual/mega-manual.html#var-
SRC_URI

--
- Scott

What's important to remember is one of the reasons for using downloadfilename is to support different files with the same name but from different sites being downloaded. This needs to work whether the file is fetched from the original source, a (PRE)MIRROR or the DL_DIR, without the files overwriting each other.

//Peter

author
#4 lore raw
In reply to Richard Purdie
Quoted 53 lines · Richard Purdie
Quoted 39 lines · Chen Qi

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://<some_mirror>/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://<some_mirror>/freeDiameter-1.4.0.tar.gz.

---
  lib/bb/fetch2/__init__.py | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
lib/bb/fetch2/__init__.py +0 -3
index 666cc1306..000b49a50 100644
@@ -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)

lib/bb/fetch2/__init__.py def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None): · line 478

Quoted 10 lines
lib/bb/fetch2/__init__.py +7 -0
+                    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)

I've been meaning to reply to this thread as the regression wasn't good. We need to be able to use DL_DIR as a mirror.

Quoted 2 lines

Could we add another test case for this case so that this doesn't regress again please?

Yes. I'll do it.

Regards,
Qi

Quoted 8 lines

Cheers,

Richard