summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/__init__.py
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2022-01-29 03:29:38 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-02-05 17:46:44 +0000
commit88993ae0308d74b4c78d28a1ff61cb20305f4e74 (patch)
tree6dcc22252a1d7ee7df5105a21e9016865f0c4603 /bitbake/lib/bb/fetch2/__init__.py
parent84963eb74ad8001b8a8961739339422c8411d79b (diff)
downloadpoky-88993ae0308d74b4c78d28a1ff61cb20305f4e74.tar.gz
bitbake: fetch2: Correct handling of replacing the basename in URIs
The solution implementated in commit 96c30007 (fetch2: fix downloadfilename issue with premirror) missed two corner cases. The first is if the basename of the original URI also appears somewhere else in the replacement URI, in which case it would also be replaced. The second is if the basename of the original URI partially matches the basename of the replacement URI, in which case the inital part of the basename from the replacement URI would be left behind. The second case caused test_npm_premirrors_with_specified_filename to fail. The solution is to prefix the basename with a slash when matching to avoid partial matches, and only replace the basename at the end of the URI. This also adds two test cases that test for these problems. Before this they would give the following errors: - ['file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz'] + ['file:///mirror/some-example-1.0.0.tgz/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz'] ? +++++ ++++++++++ - ['file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz'] + ['file:///mirror/some-some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz'] ? +++++ (Bitbake rev: 5924c6f007519cd8ea6cc8b316814d17b43048ca) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/__init__.py')
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index d37174185a..28a3e54c7f 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -473,10 +473,13 @@ def uri_replace(ud, uri_find, uri_replace, replacements, d, mirrortarball=None):
473 basename = os.path.basename(ud.localpath) 473 basename = os.path.basename(ud.localpath)
474 if basename: 474 if basename:
475 uri_basename = os.path.basename(uri_decoded[loc]) 475 uri_basename = os.path.basename(uri_decoded[loc])
476 if uri_basename and basename != uri_basename and result_decoded[loc].endswith(uri_basename): 476 # Prefix with a slash as a sentinel in case
477 result_decoded[loc] = result_decoded[loc].replace(uri_basename, basename) 477 # result_decoded[loc] does not contain one.
478 elif not result_decoded[loc].endswith(basename): 478 path = "/" + result_decoded[loc]
479 result_decoded[loc] = os.path.join(result_decoded[loc], basename) 479 if uri_basename and basename != uri_basename and path.endswith("/" + uri_basename):
480 result_decoded[loc] = path[1:-len(uri_basename)] + basename
481 elif not path.endswith("/" + basename):
482 result_decoded[loc] = os.path.join(path[1:], basename)
480 else: 483 else:
481 return None 484 return None
482 result = encodeurl(result_decoded) 485 result = encodeurl(result_decoded)