<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>5389</bug_id>
          
          <creation_ts>2013-10-28 06:41:28 +0000</creation_ts>
          <short_desc>bitbake/lib/bb/fetch2: filename too long</short_desc>
          <delta_ts>2026-01-15 16:21:33 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>BitBake</product>
          <component>bitbake</component>
          <version>1.6</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard> </status_whiteboard>
          <keywords></keywords>
          <priority>Low</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Future</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Robert Yang">liezhi.yang</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>jessica.zhang</cc>
    
    <cc>mark.asselstine</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>sgw</cc>
    
    <cc>tgamblin</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>38191</commentid>
    <comment_count>0</comment_count>
    <who name="Robert Yang">liezhi.yang</who>
    <bug_when>2013-10-28 06:41:28 +0000</bug_when>
    <thetext>When the SRC_URI is very long or the PREMIRROR/MIRROR is in a very deep directory, the fetcher of git, svn and others will covert the path into the filename, for example, path.replace(&apos;/&apos;, &apos;.&apos;), if len(path) &gt; NAME_MAX, then we will get the &quot;filename too long&quot; error, the oe-core supports to build when len(TMPDIR) &lt;= 410, but the NAME_MAX is usually 256, so we can easily get this if we put the PREMIRROR/MIRROR in a deep dir, this patch seems works, will send the PR to the mailing list later:

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 451d104..eeb55e5 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -959,6 +959,24 @@ def get_file_checksums(filelist, pn):
     checksums.sort(key=operator.itemgetter(1))
     return checksums
 
+def truncate_to_name_max(dirpath, filename):
+    &quot;&quot;&quot;
+    Truncate the filename to meet len(filename) &lt;= NAME_MAX -10, return
+    the last NAME_MAX - 10 characters if it doesn&apos;t, the -10 is for the
+    &apos;.done&apos;, &apos;.lock&apos; and perhaps others in the future.
+    &quot;&quot;&quot;
+    if not os.path.exists(dirpath):
+        bb.utils.mkdirhier(dirpath)
+
+    name_max = os.pathconf(dirpath, &apos;PC_NAME_MAX&apos;)
+    new_max = name_max - 10
+    if len(filename) &gt; new_max:
+        new_name = filename[-new_max:]
+        logger.debug(1, &quot;Truncate %s to %s to meet %s (NAME_MAX - 10) characters&quot; % \
+                    (filename, new_name, new_max))
+        filename = new_name
+
+    return filename
 
 class FetchData(object):
     &quot;&quot;&quot;
@@ -1391,7 +1409,6 @@ class Fetch(object):
                         # early checksum verify, so that if checksum mismatched,
                         # fetcher still have chance to fetch from mirror
                         update_stamp(u, ud, self.d)
-
                     except bb.fetch2.NetworkAccess:
                         raise
 
diff --git a/bitbake/lib/bb/fetch2/bzr.py b/bitbake/lib/bb/fetch2/bzr.py
index 5d9e5f9..f91c7ee 100644
--- a/bitbake/lib/bb/fetch2/bzr.py
+++ b/bitbake/lib/bb/fetch2/bzr.py
@@ -51,6 +51,8 @@ class Bzr(FetchMethod):
             ud.revision = self.latest_revision(ud.url, ud, d)
 
         ud.localfile = data.expand(&apos;bzr_%s_%s_%s.tar.gz&apos; % (ud.host, ud.path.replace(&apos;/&apos;, &apos;.&apos;), ud.revision), d)
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(ud.pkgdir, ud.localfile)
 
     def _buildbzrcommand(self, ud, d, command):
         &quot;&quot;&quot;
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 6175e4c..19598ef 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -135,9 +135,15 @@ class Git(FetchMethod):
         if ud.rebaseable:
             for name in ud.names:
                 gitsrcname = gitsrcname + &apos;_&apos; + ud.revisions[name]
+
         ud.mirrortarball = &apos;git2_%s.tar.gz&apos; % (gitsrcname)
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.mirrortarball = bb.fetch2.truncate_to_name_max(d.getVar(&quot;DL_DIR&quot;, True), ud.mirrortarball)
         ud.fullmirror = os.path.join(d.getVar(&quot;DL_DIR&quot;, True), ud.mirrortarball)
+
         gitdir = d.getVar(&quot;GITDIR&quot;, True) or (d.getVar(&quot;DL_DIR&quot;, True) + &quot;/git2/&quot;)
+        # The length of the filename should be less than NAME_MAX - 10
+        gitsrcname = bb.fetch2.truncate_to_name_max(gitdir, gitsrcname)
         ud.clonedir = os.path.join(gitdir, gitsrcname)
 
         ud.localfile = ud.clonedir
diff --git a/bitbake/lib/bb/fetch2/hg.py b/bitbake/lib/bb/fetch2/hg.py
index b1c8675..be9bb26 100644
--- a/bitbake/lib/bb/fetch2/hg.py
+++ b/bitbake/lib/bb/fetch2/hg.py
@@ -66,6 +66,9 @@ class Hg(FetchMethod):
 
         ud.localfile = data.expand(&apos;%s_%s_%s_%s.tar.gz&apos; % (ud.module.replace(&apos;/&apos;, &apos;.&apos;), ud.host, ud.path.replace(&apos;/&apos;, &apos;.&apos;), ud.revision), d)
 
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(ud.pkgdir, ud.localfile)
+
     def need_update(self, url, ud, d):
         revTag = ud.parm.get(&apos;rev&apos;, &apos;tip&apos;)
         if revTag == &quot;tip&quot;:
diff --git a/bitbake/lib/bb/fetch2/osc.py b/bitbake/lib/bb/fetch2/osc.py
index 1a3a7bb..2e276e0 100644
--- a/bitbake/lib/bb/fetch2/osc.py
+++ b/bitbake/lib/bb/fetch2/osc.py
@@ -48,6 +48,8 @@ class Osc(FetchMethod):
                 ud.revision = &quot;&quot;
 
         ud.localfile = data.expand(&apos;%s_%s_%s.tar.gz&apos; % (ud.module.replace(&apos;/&apos;, &apos;.&apos;), ud.path.replace(&apos;/&apos;, &apos;.&apos;), ud.revision), d)
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(ud.pkgdir, ud.localfile)
 
     def _buildosccommand(self, ud, d, command):
         &quot;&quot;&quot;
diff --git a/bitbake/lib/bb/fetch2/repo.py b/bitbake/lib/bb/fetch2/repo.py
index 8300da8..1e46968 100644
--- a/bitbake/lib/bb/fetch2/repo.py
+++ b/bitbake/lib/bb/fetch2/repo.py
@@ -52,6 +52,8 @@ class Repo(FetchMethod):
             ud.manifest += &apos;.xml&apos;
 
         ud.localfile = data.expand(&quot;repo_%s%s_%s_%s.tar.gz&quot; % (ud.host, ud.path.replace(&quot;/&quot;, &quot;.&quot;), ud.manifest, ud.branch), d)
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(d.getVar(&quot;DL_DIR&quot;, True), ud.localfile)
 
     def download(self, loc, ud, d):
         &quot;&quot;&quot;Fetch url&quot;&quot;&quot;
@@ -62,6 +64,8 @@ class Repo(FetchMethod):
 
         gitsrcname = &quot;%s%s&quot; % (ud.host, ud.path.replace(&quot;/&quot;, &quot;.&quot;))
         repodir = data.getVar(&quot;REPODIR&quot;, d, True) or os.path.join(data.getVar(&quot;DL_DIR&quot;, d, True), &quot;repo&quot;)
+        # The length of the filename should be less than NAME_MAX - 10
+        gitsrcname = bb.fetch2.truncate_to_name_max(repodir, gitsrcname)
         codir = os.path.join(repodir, gitsrcname, ud.manifest)
 
         if ud.user:
diff --git a/bitbake/lib/bb/fetch2/svk.py b/bitbake/lib/bb/fetch2/svk.py
index ee3823f..dbd78f3 100644
--- a/bitbake/lib/bb/fetch2/svk.py
+++ b/bitbake/lib/bb/fetch2/svk.py
@@ -53,6 +53,8 @@ class Svk(FetchMethod):
         ud.revision = ud.parm.get(&apos;rev&apos;, &quot;&quot;)
 
         ud.localfile = data.expand(&apos;%s_%s_%s_%s_%s.tar.gz&apos; % (ud.module.replace(&apos;/&apos;, &apos;.&apos;), ud.host, ud.path.replace(&apos;/&apos;, &apos;.&apos;), ud.revision, ud.date), d)
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(d.getVar(&quot;DL_DIR&quot;, True), ud.localfile)
 
     def need_update(self, url, ud, d):
         if ud.date == &quot;now&quot;:
diff --git a/bitbake/lib/bb/fetch2/svn.py b/bitbake/lib/bb/fetch2/svn.py
index 9a779d2..c155735 100644
--- a/bitbake/lib/bb/fetch2/svn.py
+++ b/bitbake/lib/bb/fetch2/svn.py
@@ -65,6 +65,9 @@ class Svn(FetchMethod):
 
         ud.localfile = data.expand(&apos;%s_%s_%s_%s_.tar.gz&apos; % (ud.module.replace(&apos;/&apos;, &apos;.&apos;), ud.host, ud.path.replace(&apos;/&apos;, &apos;.&apos;), ud.revision), d)
 
+        # The length of the filename should be less than NAME_MAX - 10
+        ud.localfile = bb.fetch2.truncate_to_name_max(ud.pkgdir, ud.localfile)
+
     def _buildsvncommand(self, ud, d, command):
         &quot;&quot;&quot;
         Build up an svn commandline based on ud</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83075</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2019-02-21 16:31:53 +0000</bug_when>
    <thetext>I think we may need to do something which is more context aware to ensure we preserve the most critical pieces of the filename which may be at the start or end or elsewhere depending on the fetcher implementation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93503</commentid>
    <comment_count>2</comment_count>
    <who name="Mark">mark.asselstine</who>
    <bug_when>2022-06-13 20:00:09 +0000</bug_when>
    <thetext>I agree with Richard. Truncation is most likely removing the most valuable disambiguation part of the filename. ie. host and path are more likely to be used for multiple SRC_URIs.

Additionally the various git.py, svn.py... have a better view of the string and thus can do a better job of handling how best to shrink the filename. For example for git it makes sense to keep the hostname and drop the first parts of the pathname (again they are more likely to be non-unique).

Instead of just dropping characters should we instead use some sort of ellipses? Is there any opportunity to know that a PREMIRROR is being used which we can drop? Maybe we should just start to catching the overflow occurrences and providing a better error/warning message.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96106</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-07-26 21:22:07 +0000</bug_when>
    <thetext>Bulk move of 64 bugs to 4.3 M3 after a quick review.
If a bug is actually fixed, please add a commit link and resolve it.
-- Randy for YP bug team.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>96428</commentid>
    <comment_count>4</comment_count>
    <who name="Trevor Gamblin">tgamblin</who>
    <bug_when>2023-09-14 15:42:45 +0000</bug_when>
    <thetext>Moved to M4.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97094</commentid>
    <comment_count>5</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-10-30 15:29:16 +0000</bug_when>
    <thetext>Bulk move to 5.0 M1. -- Randy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97641</commentid>
    <comment_count>6</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2023-12-21 20:41:50 +0000</bug_when>
    <thetext>This hasn&apos;t been fixed or discussed much since 2013, I&apos;ve lowered the importance and set the milestone to future.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>