diff mbox series

[V2] patch.py: add checks for patch_path

Message ID 20260114125207.497436-1-oobitots@cisco.com
State New
Headers show
Series [V2] patch.py: add checks for patch_path | expand

Commit Message

Oleksiy Obitotskyy Jan. 14, 2026, 12:52 p.m. UTC
All URLs from SRC checked to be a patch.
In some rare cases, when we have "diff" or
"patch" into URL it is treated as a patch not
like proper resource (e.g. repository). This
happens in case of using mirrors. Without
pre-downloaded repository archive we have
directory into downloads and exit from
patch_path before checking for patch/diff.

Let's limit patch_path call for url's that
has "apply" parameter set or has original
extensions .diff or .patch.

Error example for this URL:
git://github.com/pkg/diff;name=diff;\
destsuffix=build/vendor/src/github.com/pkg/diff;branch=main;protocol=https

ERROR: nativesdk-yq-4.30.8+gitdd6cf3df146f3e2c0f8c765a6ef9e35780ad8cc1-r0 do_patch: \
Importing patch 'github.com.pkg.diff' with striplevel '1'
FileNotFoundError(2, 'No such file or directory')

Signed-off-by: Oleksiy Obitotskyy <oobitots@cisco.com>
---
 meta/lib/oe/patch.py | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

Comments

Paul Barker Jan. 14, 2026, 1:39 p.m. UTC | #1
On Wed, 2026-01-14 at 04:52 -0800, Oleksiy Obitotskyy via
lists.openembedded.org wrote:
> All URLs from SRC checked to be a patch.
> In some rare cases, when we have "diff" or
> "patch" into URL it is treated as a patch not
> like proper resource (e.g. repository). This
> happens in case of using mirrors. Without
> pre-downloaded repository archive we have
> directory into downloads and exit from
> patch_path before checking for patch/diff.
> 
> Let's limit patch_path call for url's that
> has "apply" parameter set or has original
> extensions .diff or .patch.
> 
> Error example for this URL:
> git://github.com/pkg/diff;name=diff;\
> destsuffix=build/vendor/src/github.com/pkg/diff;branch=main;protocol=https
> 
> ERROR: nativesdk-yq-4.30.8+gitdd6cf3df146f3e2c0f8c765a6ef9e35780ad8cc1-r0 do_patch: \
> Importing patch 'github.com.pkg.diff' with striplevel '1'
> FileNotFoundError(2, 'No such file or directory')
> 
> Signed-off-by: Oleksiy Obitotskyy <oobitots@cisco.com>

You mention the `apply` parameter in your commit message. Can you just
add `;apply=no` to the relevant SRC_URI entry?

Best regards,
diff mbox series

Patch

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 246fc6221f..c5d09a399f 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -884,6 +884,33 @@  class UserResolver(Resolver):
         finally:
             os.chdir(olddir)
 
+def is_archive_extension(ext):
+    return ext in ('.gz', '.bz2', '.xz', '.Z')
+
+def is_patch_extension(ext):
+    return ext in ('.diff', '.patch')
+
+def could_be_patch(url):
+    """
+    URI could be treated as patch if:
+    - any resource with parameter apply set to yes/true
+    - any resource without parameter apply explicitly set, but let's limit them to ones with
+      extension .patch or .diff
+    """
+    (_, _, path, _, _, parm) = bb.fetch.decodeurl(url)
+
+    if "apply" in parm:
+        apply = oe.types.boolean(parm["apply"])
+        if apply:
+            return True
+
+    base, ext = os.path.splitext(path)
+    if is_archive_extension(ext):
+        _, ext = os.path.splitext(base)
+    if is_patch_extension(ext):
+       return True
+
+    return False
 
 def patch_path(url, fetch, unpackdir, expand=True):
     """Return the local path of a patch, or return nothing if this isn't a patch"""
@@ -892,7 +919,7 @@  def patch_path(url, fetch, unpackdir, expand=True):
     if os.path.isdir(local):
         return
     base, ext = os.path.splitext(os.path.basename(local))
-    if ext in ('.gz', '.bz2', '.xz', '.Z'):
+    if is_archive_extension(ext):
         if expand:
             local = os.path.join(unpackdir, base)
         ext = os.path.splitext(base)[1]
@@ -902,7 +929,7 @@  def patch_path(url, fetch, unpackdir, expand=True):
         apply = oe.types.boolean(urldata.parm["apply"])
         if not apply:
             return
-    elif ext not in (".diff", ".patch"):
+    elif not is_patch_extension(ext):
         return
 
     return local
@@ -913,7 +940,9 @@  def src_patches(d, all=False, expand=True):
     patches = []
     sources = []
     for url in fetch.urls:
-        local = patch_path(url, fetch, unpackdir, expand)
+        local = None
+        if could_be_patch(url):
+            local = patch_path(url, fetch, unpackdir, expand)
         if not local:
             if all:
                 local = fetch.localpath(url)