From f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Mon, 28 Sep 2020 17:18:58 +0100 Subject: bitbake: utils: add umask changing context manager Add a umask context manager which can be used to temporarily change the umask in a 'with' block. (Bitbake rev: 6c601e68a27e1c60b04c2a61830d1812cc883e09) Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bitbake') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 0b79f92e25..f73d31fb73 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -944,6 +944,17 @@ def which(path, item, direction = 0, history = False, executable=False): return "", hist return "" +@contextmanager +def umask(new_mask): + """ + Context manager to set the umask to a specific mask, and restore it afterwards. + """ + current_mask = os.umask(new_mask) + try: + yield + finally: + os.umask(current_mask) + def to_boolean(string, default=None): if not string: return default -- cgit v1.2.3-54-g00ecf