diff mbox series

fetch/wget: Handle long filenames correctly

Message ID 20260810111231.2610507-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series fetch/wget: Handle long filenames correctly | expand

Commit Message

Richard Purdie Aug. 10, 2026, 11:12 a.m. UTC
Long filenames, which may happen through sstate, were being handled incorrectly
as they could exceed max path lengths when '.tmp' was added.

Handle those cases by using slightly shorter filenames if that happens for the
intermediate tmp file.

[YOCTO #16293]

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/fetch2/wget.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 141c2d062d0..1e5d20132c3 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -106,7 +106,10 @@  class Wget(FetchMethod):
         fetchcmd = self.basecmd.copy()
 
         dldir = os.path.realpath(d.getVar("DL_DIR"))
-        localpath = os.path.join(dldir, ud.localfile) + ".tmp"
+        # Where we ultimately want the file
+        finalpath = os.path.join(dldir, ud.localfile)
+        # A temp location while processing, keeping in mind max path lengths
+        localpath = finalpath[:250] + ".tmp"
         bb.utils.mkdirhier(os.path.dirname(localpath))
         fetchcmd.append("--output-document=%s" % localpath)
 
@@ -146,7 +149,7 @@  class Wget(FetchMethod):
 
         # Remove the ".tmp" and move the file into position atomically
         # Our lock prevents multiple writers but mirroring code may grab incomplete files
-        os.rename(localpath, localpath[:-4])
+        os.rename(localpath, finalpath)
 
         return True