diff options
author | Ross Burton <ross@burtonini.com> | 2020-09-28 17:18:58 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-10 14:01:01 +0000 |
commit | 6ca998054e422da72c7906d3ec4f204d88c32ee0 (patch) | |
tree | 28745da3118eeb18ae754386d1bca79f5f1d18e5 /lib | |
parent | 3c7b210e9599058a48d0c38ce8034b94e2d0f781 (diff) | |
download | bitbake-contrib-6ca998054e422da72c7906d3ec4f204d88c32ee0.tar.gz |
utils: add umask changing context manager
Add a umask context manager which can be used to temporarily change the
umask in a 'with' block.
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bb/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 1a5a0aae6..34fa0b7a6 100644 --- a/lib/bb/utils.py +++ b/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 |