All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fetch2/git.py: Check if clonedir is correct after shallow tarball clone
@ 2022-02-10 13:27 Tomasz Dziendzielski
  2022-02-10 13:31 ` [bitbake-devel] " Alexander Kanavin
  0 siblings, 1 reply; 9+ messages in thread
From: Tomasz Dziendzielski @ 2022-02-10 13:27 UTC (permalink / raw)
  To: bitbake-devel; +Cc: pavel, Tomasz Dziendzielski, Jan Brzezanski

If shallow tarball clone is used and if tar unpacking fails for any
reason it might end up with empty directory created. Since runfetchcmd
does not check any return code we might not detect the issue and we will
not clone from git. Then due to missing hash it will replace main
repository's git remote with the remote of failing recipe.

To fix this behaviour we'll check if clonedir is not empty and if git
dir is the same as clonedir.

Signed-off-by: Tomasz Dziendzielski <tomasz.dziendzielski@gmail.com>
Signed-off-by: Jan Brzezanski <jan.brzezanski@gmail.com>
---
 lib/bb/fetch2/git.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 30da8e95..ed6ecb64 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -356,8 +356,15 @@ class Git(FetchMethod):
 
         repourl = self._get_repo_url(ud)
 
-        # If the repo still doesn't exist, fallback to cloning it
-        if not os.path.exists(ud.clonedir):
+        # Clean repo if git dir is different than ud.clonedir, which means tar unpacking failed
+        if os.path.exists(ud.clonedir):
+            if ud.clonedir != runfetchcmd("%s -C %s rev-parse --git-dir" % (ud.basecmd, ud.clonedir), d):
+                bb.utils.remove(ud.clonedir, recurse=True)
+                bb.utils.mkdirhier(ud.clonedir)
+                os.chdir(ud.clonedir)
+
+        # If the repo still doesn't exist or is empty, fallback to cloning it
+        if not os.path.exists(ud.clonedir) or not os.listdir(ud.clonedir):
             # We do this since git will use a "-l" option automatically for local urls where possible
             if repourl.startswith("file://"):
                 repourl = repourl[7:]
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-10 17:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-10 13:27 [PATCH v2] fetch2/git.py: Check if clonedir is correct after shallow tarball clone Tomasz Dziendzielski
2022-02-10 13:31 ` [bitbake-devel] " Alexander Kanavin
2022-02-10 13:39   ` Tomasz Dziendzielski
2022-02-10 14:08   ` Pavel Zhukov
2022-02-10 14:22     ` Tomasz Dziendzielski
2022-02-10 14:40       ` Pavel Zhukov
2022-02-10 14:58         ` Tomasz Dziendzielski
     [not found]         ` <16D27480B462D202.11771@lists.openembedded.org>
2022-02-10 15:24           ` Tomasz Dziendzielski
2022-02-10 17:23             ` Pavel Zhukov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.