diff mbox series

[RFC,v2,5/7] fetch2: add helper to get urldata in Fetch class

Message ID 20250905064419.2589111-6-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series fetch2: add support for implicit urls | expand

Commit Message

Stefan Herbrechtsmeier Sept. 5, 2025, 6:44 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Add a private helper function to get the urldata object of a given URL.
Create the urldate object if it doesn't exist inside the urldata object
list of the fetch object.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

(no changes since v1)

 lib/bb/fetch2/__init__.py | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index 3ff08f817..c4d7cc033 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -1829,11 +1829,9 @@  class Fetch(object):
             urldata_cache[key] = self.ud
 
     def localpath(self, url):
-        if url not in self.urls:
-            self.ud[url] = FetchData(url, self.d)
-
-        self.ud[url].setup_localpath(self.d)
-        return self.ud[url].localpath
+        ud = self._get_urldata(url)
+        ud.setup_localpath(self.d)
+        return ud.localpath
 
     def localpaths(self):
         """
@@ -1842,7 +1840,7 @@  class Fetch(object):
         local = []
 
         def localpath(url):
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             ud.setup_localpath(self.d)
             local.append(ud.localpath)
 
@@ -1863,7 +1861,7 @@  class Fetch(object):
 
         checksum_missing_messages = []
         def download(url):
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             ud.setup_localpath(self.d)
             m = ud.method
             done = False
@@ -1979,7 +1977,7 @@  class Fetch(object):
             urls = self.urls
 
         def checkstatus(url):
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             ud.setup_localpath(self.d)
             m = ud.method
             logger.debug("Testing URL %s", url)
@@ -2011,7 +2009,7 @@  class Fetch(object):
         unpack_tracer.start(root, self.ud, self.d)
 
         def unpack(url):
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             ud.setup_localpath(self.d)
 
             if ud.lockfile:
@@ -2038,9 +2036,7 @@  class Fetch(object):
             urls = self.urls
 
         def clean(url):
-            if url not in self.ud:
-                self.ud[url] = FetchData(url, self.d)
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             ud.setup_localpath(self.d)
 
             if not ud.localfile and ud.localpath is None:
@@ -2071,7 +2067,7 @@  class Fetch(object):
 
         urldata = []
         def expand_urldata(url):
-            ud = self.ud[url]
+            ud = self._get_urldata(url)
             urldata.append(ud)
             urldata.extend(ud.method.implicit_urldata(ud, self.d))
 
@@ -2080,6 +2076,12 @@  class Fetch(object):
 
         return urldata
 
+    def _get_urldata(self, url):
+        if url not in self.ud:
+            self.ud[url] = FetchData(url, self.d)
+            self.ud[url].unpack_tracer = unpack_tracer
+        return self.ud[url]
+
 class FetchConnectionCache(object):
     """
         A class which represents an container for socket connections.