diff mbox series

[4/6] utils: Allow lockfile/unlockfile to take empty names

Message ID 20260813124834.1770307-4-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/6] fetch/__init__: Clean up minor mirror code duplication | expand

Commit Message

Richard Purdie Aug. 13, 2026, 12:48 p.m. UTC
I've been torn on whether to allow this for a long time. The context manager
does allow it and it does allow code simplification if it can just accept
no locks are present so on balance, it is probably slightly neater.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 8b8d381faa5..92b60b39d2c 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -529,6 +529,9 @@  def lockfile(name, shared=False, retry=True, block=False):
 
     Returns the locked file descriptor in case of success, ``None`` otherwise.
     """
+    if not name:
+        return None
+
     basename = os.path.basename(name)
     if len(basename) > 255:
         root, ext = os.path.splitext(basename)
@@ -594,6 +597,9 @@  def unlockfile(lf):
 
     No return value.
     """
+    if not lf:
+        return
+
     try:
         # If we had a shared lock, we need to promote to exclusive before
         # removing the lockfile. Attempt this, ignore failures.