fetch2/git: replace stale clones when using premirrors
Hi,
A gentle reminder about this patch. It is still listed as New in Patchwork, and I have not seen any review comments.
The patch prevents a successful premirror fetch from leaving a stale Git clone at the original download path, which otherwise causes a later do_unpack failure.
I noticed that bb.fetch2 has since been renamed to bb.fetch. I can send a rebased v3 if that would make review easier. Please let me know if the approach needs any changes.
Thanks,
Fredrik
________________________________
From: [email protected] <[email protected]> on behalf of Fredrik Svensson via lists.openembedded.org <[email protected]>
Sent: Monday, August 24, 2026 1:29 PM
To: [email protected] <[email protected]>
Subject: [bitbake-devel] [PATCH v2] fetch2/git: replace stale clones when using premirrors
A successful premirror fetch can leave an existing clone at the original download path even when it lacks SRCREV. The fetch is then stamped complete before unpack rejects the stale clone.
Pass the datastore to update_mirror_links() and remove the original clone only when the Git validity check says it needs updating, allowing the successful mirror to be linked.
The new self-test creates a stale clone at the original download path and a local premirror containing a newer SRCREV. Without the fix it reproduces the UnpackError; with the fix it verifies that the mirror is linked and the requested revision is unpacked.
Tested with bitbake-selftest on Python 3.11, 3.12, 3.13, and 3.14.
AI-Generated: OpenAI Codex
--- lib/bb/fetch2/__init__.py | 4 ++-- lib/bb/fetch2/git.py | 8 ++++++-- lib/bb/tests/fetch.py | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-)
lib/bb/fetch2/__init__.py +2 -2
@@ -1150,7 +1150,7 @@ def try_mirror_url(fetch, origud, ud, ld, check = False): # This may also be a link to a shallow archive # When using shallow mode, add a symlink to the original fullshallow # path to ensure a valid symlink even in the `PREMIRRORS` case - origud.method.update_mirror_links(ud, origud) + origud.method.update_mirror_links(ud, origud, ld) update_stamp(origud, ld) return ud.localpath
@@ -1692,7 +1692,7 @@ class FetchMethod(object): except FileExistsError: pass - def update_mirror_links(self, ud, origud): + def update_mirror_links(self, ud, origud, d): # For local file:// results, create a symlink to them # This may also be a link to a shallow archive self.ensure_symlink(ud.localpath, origud.localpath)
lib/bb/fetch2/git.py +6 -2
@@ -353,8 +353,12 @@ class Git(FetchMethod): def tarball_need_update(self, ud): return ud.write_tarballs and not os.path.exists(ud.fullmirror) - def update_mirror_links(self, ud, origud): - super().update_mirror_links(ud, origud) + def update_mirror_links(self, ud, origud, d): + # Replace a stale clone which would prevent linking the successful mirror. + if self.clonedir_need_update(origud, d) and os.path.exists(origud.localpath) \ + and not os.path.samefile(ud.localpath, origud.localpath): + bb.utils.remove(origud.localpath, recurse=True) + super().update_mirror_links(ud, origud, d) # When using shallow mode, add a symlink to the original fullshallow # path to ensure a valid symlink even in the `PREMIRRORS` case if origud.shallow and not os.path.exists(origud.fullshallow):
lib/bb/tests/fetch.py +42 -0
48 lines not on this page · raw message
--
2.55.0
Quoted 17 lines · Fredrik Svensson via lists.openembedded.org
A gentle reminder about this patch. It is still listed as New in Patchwork, and I have not seen any review comments.
The patch prevents a successful premirror fetch from leaving a stale Git
clone at the original download path, which otherwise causes a laterdo_unpackfailure.I noticed that bb.fetch2 has since been renamed to bb.fetch. I can send a
rebased v3 if that would make review easier. Please let me know if the
approach needs any changes.
Quoted 2 lines
It definitely hasn't been forgotten and is in the queue. I was trying to find time to provide helpful feedback rather than just saying it wasn't right.
Firstly, I don't think the fetcher should be deleting data like that, if it is stale, it should just pass over and ignore it as something else my want or be using it. For that reason I couldn't merge this as is.
I do appreciate you're fixing a real issue here though and therefore the question is how to do that.
The fetcher has traditionally struggled in this area and it isn't been clear how to handle things from the code perspective. The "update_mirror_links" was one way we've attempted that but it is clearly flawed.
I'd note a recent change I made for sort of related reasons may be helpful:
https://git.openembedded.org/bitbake/commit/?id=58872250f72f5760b4126552bdec5497f5a1a1f4
I'm wondering if we can use the presence of "origud" as a way to build any mirror link when the fetch succeeds and maybe remove update_mirror_links entirely instead?
Cheers,
Richard
Hi Richard,
Thanks for the feedback. I agree that deleting the existing clone is not appropriate when DL_DIR may be shared with other builds.
The origud reference added by 58872250 looks like a useful way forward. Instead of replacing the stale path, I will look at making the successful mirror data available to the original fetch operation so that unpack can use it directly. The stale clone would then be left untouched.
I will also investigate removing update_mirror_links as part of that change, as you suggested.
I will rebase onto current master and update the test to verify that the requested revision is unpacked from the premirror while the stale original clone remains unchanged.
Thanks,
Fredrik
________________________________
From: [email protected] <[email protected]> on behalf of Richard Purdie via lists.openembedded.org <[email protected]>
Sent: Thursday, September 10, 2026 7:19 PM
To: Fredrik Svensson (svsvenss) <[email protected]>; [email protected] <[email protected]>
Subject: Re: [bitbake-devel] [PATCH v2] fetch2/git: replace stale clones when using premirrors
Quoted 17 lines · Fredrik Svensson via lists.openembedded.org
A gentle reminder about this patch. It is still listed as New in Patchwork, and I have not seen any review comments.
The patch prevents a successful premirror fetch from leaving a stale Git
clone at the original download path, which otherwise causes a laterdo_unpackfailure.I noticed that bb.fetch2 has since been renamed to bb.fetch. I can send a
rebased v3 if that would make review easier. Please let me know if the
approach needs any changes.
Quoted 2 lines
It definitely hasn't been forgotten and is in the queue. I was trying to find time to provide helpful feedback rather than just saying it wasn't right.
Firstly, I don't think the fetcher should be deleting data like that, if it is stale, it should just pass over and ignore it as something else my want or be using it. For that reason I couldn't merge this as is.
I do appreciate you're fixing a real issue here though and therefore the question is how to do that.
The fetcher has traditionally struggled in this area and it isn't been clear how to handle things from the code perspective. The "update_mirror_links" was one way we've attempted that but it is clearly flawed.
I'd note a recent change I made for sort of related reasons may be helpful:
https://git.openembedded.org/bitbake/commit/?id=58872250f72f5760b4126552bdec5497f5a1a1f4
I'm wondering if we can use the presence of "origud" as a way to build any mirror link when the fetch succeeds and maybe remove update_mirror_links entirely instead?
Cheers,
Richard