Skip to contentSkip to conversation

fetch2: Drop DL_DIR fallback for local file fetcher

PATCH New Richard Purdie 1 participant 2 messages Jul 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fetch2: Drop DL_DIR fallback for local file fetcher

A long time ago, we made DL_DIR a final fallback for the local fetcher. Since then we added checksum support and task hashes and the world has changed. There were warnings added some time ago if this fallback triggers and it is now time to drop it entirely.

The original use case was for sstate however the sstate code now sets FILESPATH correctly so DL_DIR is no longer needed.

There have been a few small bugs exposed by this change, missing mkdir calls and some minor test issues that needed tweaks. In general this simplifies and improves the fetcher code flow though.

This completes a cleanup that ensures local files are correctly covered at parse time which ensures rebuilds and reparses happen at the right times.

---
 lib/bb/fetch2/__init__.py | 16 ++++++----------
 lib/bb/fetch2/local.py    |  8 --------
 lib/bb/tests/fetch.py     |  2 ++
 3 files changed, 8 insertions(+), 18 deletions(-)
lib/bb/fetch2/__init__.py +6 -10
index cd7dc4f132..3eda9bbe70 100644
@@ -1220,25 +1220,21 @@ def get_checksum_file_list(d):
     SRC_URI as a space-separated string
     """
     fetch = Fetch([], d, cache = False, localonly = True)
-
-    dl_dir = d.getVar('DL_DIR')
     filelist = []
     for u in fetch.urls:
         ud = fetch.ud[u]
-
         if ud and isinstance(ud.method, local.Local):
+            found = False
             paths = ud.method.localpaths(ud, d)
             for f in paths:
                 pth = ud.decodedurl
-                if f.startswith(dl_dir):
-                    # The local fetcher's behaviour is to return a path under DL_DIR if it couldn't find the file anywhere else
-                    if os.path.exists(f):
-                        bb.warn("Getting checksum for %s SRC_URI entry %s: file not found except in DL_DIR" % (d.getVar('PN'), os.path.basename(f)))
-                    else:
-                        bb.fatal(("Unable to get checksum for %s SRC_URI entry %s: file could not be found"
+                if os.path.exists(f):
+                    found = True
+                filelist.append(f + ":" + str(os.path.exists(f)))
+            if not found:
+                bb.fatal(("Unable to get checksum for %s SRC_URI entry %s: file could not be found"
                             "\nThe following paths were searched:"
                             "\n%s") % (d.getVar('PN'), os.path.basename(f), '\n'.join(paths)))
-                filelist.append(f + ":" + str(os.path.exists(f)))
 
     return " ".join(filelist)
 
lib/bb/fetch2/local.py +0 -8
index e7d1c8c58f..0bb987c644 100644
@@ -57,12 +57,6 @@ class Local(FetchMethod):
             logger.debug2("Searching for %s in paths:\n    %s" % (path, "\n    ".join(filespath.split(":"))))
             newpath, hist = bb.utils.which(filespath, path, history=True)
             searched.extend(hist)
-        if not os.path.exists(newpath):
-            dldirfile = os.path.join(d.getVar("DL_DIR"), path)
-            logger.debug2("Defaulting to %s for %s" % (dldirfile, path))
-            bb.utils.mkdirhier(os.path.dirname(dldirfile))
-            searched.append(dldirfile)
-            return searched
         return searched
 
     def need_update(self, ud, d):
@@ -78,8 +72,6 @@ class Local(FetchMethod):
             filespath = d.getVar('FILESPATH')
             if filespath:
                 locations = filespath.split(":")
-            locations.append(d.getVar("DL_DIR"))
-
             msg = "Unable to find file " + urldata.url + " anywhere. The paths that were searched were:\n    " + "\n    ".join(locations)
             raise FetchError(msg)
 
lib/bb/tests/fetch.py +2 -0
index 20d7953f35..7fcf57e7ea 100644
@@ -468,6 +468,7 @@ class MirrorUriTest(FetcherTest):
                 "http://.*/.* file:///someotherpath/downloads/"
 
     def test_urireplace(self):
+        self.d.setVar("FILESPATH", ".")
         for k, v in self.replaceuris.items():
             ud = bb.fetch.FetchData(k[0], self.d)
             ud.setup_localpath(self.d)
@@ -925,6 +926,7 @@ class FetcherNetworkTest(FetcherTest):
 
     @skipIfNoNetwork()
     def test_fetch_file_mirror_of_mirror(self):
+        self.d.setVar("FILESPATH", ".")
         self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ file:///some1where/.* file://some2where/ file://some2where/.* https://downloads.yoctoproject.org/releases/bitbake")
         fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d)
         os.mkdir(self.dldir + "/some2where")
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 fetch2: Ensure directory exists before creating symlink

If the mirrors code is trying to create a symlink and the parent directory doesn't exist, as might be the case for sstate mirrors where the fetch is into a subdir, it can silently fail.

Ensure the directory exists in this case to avoid issues.

---
 lib/bb/fetch2/__init__.py | 2 ++
 1 file changed, 2 insertions(+)
lib/bb/fetch2/__init__.py +2 -0
index 3eda9bbe70..0fb718b23e 100644
@@ -1097,6 +1097,8 @@ def try_mirror_url(fetch, origud, ud, ld, check = False):
 
 def ensure_symlink(target, link_name):
     if not os.path.exists(link_name):
+        dirname = os.path.dirname(link_name)
+        bb.utils.mkdirhier(dirname)
         if os.path.islink(link_name):
             # Broken symbolic link
             os.unlink(link_name)
Signature · 1 line
2.34.1