diff mbox series

[3/7] license_finder: do not match files that have no license text

Message ID 20261201034910.25521-4-tim.orling@konsulko.com
State New
Headers show
Series go-mod-update-modules: identify licenses with licensecheck | expand

Commit Message

Tim Orling Dec. 1, 2026, 3:49 a.m. UTC
_crunch_license() drops titles, copyright lines and URLs, so a file with
nothing else hashes as an empty text, as does
common-licenses/Proprietary. Such a file matched "Proprietary", which is
not an SPDX identifier, and go-mod-update-modules failed with
"Unknown Expression 'Proprietary'".

Return None when no text is left, and do not register None as the hash
of a known license. An exact copy of a license file still matches by its
plain md5.

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 meta/lib/oe/license_finder.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py
index d08d4af5d2..cd290adf59 100644
--- a/meta/lib/oe/license_finder.py
+++ b/meta/lib/oe/license_finder.py
@@ -55,7 +55,8 @@  def _crunch_known_licenses(d):
             md5sums[md5value] = fn
             # Also hash a "crunched" version
             md5value = _crunch_license(path)
-            md5sums[md5value] = fn
+            if md5value:
+                md5sums[md5value] = fn
 
     return md5sums
 
@@ -115,6 +116,11 @@  def _crunch_license(licfile):
             if line:
                 lictext.append(line)
 
+    # Only titles, copyright lines or URLs: there is no license text to
+    # compare, and an empty text would match every other empty text
+    if not lictext:
+        return None
+
     m = hashlib.md5()
     try:
         m.update(' '.join(lictext).encode('utf-8'))