diff options
author | 2020-09-28 17:18:58 +0100 | |
---|---|---|
committer | 2020-09-30 15:03:30 +0100 | |
commit | f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588 (patch) | |
tree | e354f8c5069101339c95ee0475ea55626beca6d0 /bitbake | |
parent | f6609eebca510b298f46074059f1643017166a49 (diff) | |
download | poky-f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588.tar.gz poky-f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588.tar.bz2 poky-f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588.zip |
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 <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
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 |