From 658a3832def72d6fd904d89e368b13942b477cbd 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: 6ca998054e422da72c7906d3ec4f204d88c32ee0) Signed-off-by: Ross Burton Signed-off-by: Richard Purdie Signed-off-by: Steve Sakoman --- bitbake/lib/bb/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 1a5a0aae6c..34fa0b7a67 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -969,6 +969,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