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

Richard Purdie <[email protected]>
Newsgroups org.openembedded.lists.bitbake-devel
Message-ID <[email protected]>
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 <[email protected]>
---
 lib/bb/utils.py | 6 ++++++
 1 file changed, 6 insertions(+)

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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.