From 7a8eb8da8e8495051e174721062da08e06168024 Mon Sep 17 00:00:00 2001 From: Joshua Watt Date: Aug 31 2022 09:40:00 +0000 Subject: utils: Pass lock argument in fileslocked Pass additional arguments in the fileslocked() context manager to the underlying lockfile() function. This allows the context manager to be used for any types of locks (non-blocking, shared, etc.) that the lockfile() function supports. Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- diff --git a/lib/bb/utils.py b/lib/bb/utils.py index b8b90df..92d44c5 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -431,12 +431,14 @@ def better_eval(source, locals, extraglobals = None): return eval(source, ctx, locals) @contextmanager -def fileslocked(files): +def fileslocked(files, *args, **kwargs): """Context manager for locking and unlocking file locks.""" locks = [] if files: for lockfile in files: - locks.append(bb.utils.lockfile(lockfile)) + l = bb.utils.lockfile(lockfile, *args, **kwargs) + if l is not None: + locks.append(l) try: yield