[bitbake-devel] bitbake: fetch2: try_mirror_url(): Replace old git with mirror

Submitted by Ernst Sjöstrand on May 10, 2019, 12:30 p.m. | Patch ID: 161135


Message ID d7b161c175927f11ad6933aa200f8aad79fbb30e.camel@verisure.com
State New
Headers show

Commit Message

Ernst Sjöstrand May 10, 2019, 12:30 p.m.
If we're trying to fetch a git, we're in try_mirror_url and
origud.localpath is a directory, that means the original clone is broken
for some reason but we found a mirror that works.
Remove the original clone and replace it with a symlink, like what would
hopefully be done on a fresh fetch.

[ Yocto # 13278 ]

Signed-off-by: Ernst Sjöstrand <ernst.sjostrand@verisure.com>

 bitbake/lib/bb/fetch2/__init__.py | 6 ++++++
 1 file changed, 6 insertions(+)


Patch hide | download patch | download mbox

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 72d6092deb..be1228d6d5 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -33,6 +33,7 @@  if 'git' not in urllib.parse.uses_netloc:
 import operator
 import collections
+import shutil
 import subprocess
 import pickle
 import errno
@@ -1015,6 +1016,11 @@  def try_mirror_url(fetch, origud, ud, ld, check = False):
                 if hasattr(origud.method, "build_mirror_data"):
                     origud.method.build_mirror_data(origud, ld)
             return origud.localpath
+        if isinstance(ud.method, git.Git) and os.path.isdir(origud.localpath) and origud.localpath != ud.localpath:
+            logger.warning("Replacing %s with link to %s", origud.localpath, ud.localpath)
+            # We have an old git clone here which is broken for some reason,
+            # remove it and replace is with a symlink.
+            shutil.rmtree(origud.localpath)
         # Otherwise the result is a local file:// and we symlink to it
         if not os.path.exists(origud.localpath):
             if os.path.islink(origud.localpath):